is it possible to add a choice list in configureformfields with choices values mapped from the database instead of configuring it manually like this :
->add('testfield', 'choice', array('choices' => array(
'1' => 'choice 1',
'2' => 'choice 2',)))
if the entity is correctly mapped then you can just use:
->add('testfield')
and Sonata admin will do the job.
Let's say you have a Product class linked to a Category class:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* #ORM\Table(name="product")
*
*/
class Product
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Category", inversedBy="products")
*/
protected $category;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set category
*
* #param Category $category
*
* #return Product
*/
public function setCategory(Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return Category
*/
public function getCategory()
{
return $this->category;
}
}
Simply using:
->add('category')
will provide a select form field with all the categories.
You can also use SONATA_TYPE_MODEL if you want something more advanced:
<?php
// src/AppBundle/Admin/ProductAdmin.php
class ProductAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$imageFieldOptions = array(); // see available options below
$formMapper
->add('category', 'sonata_type_model', $imageFieldOptions)
;
}
}
The documentation is on this page: Form Types
Hope this helps!
Related
I have an issue with some entities : according to the doctrine documentation, lazy loading should allow me to load my collection only when I call the getters, but it doesn't.
Here is the relation description :
One Location has many Venues, mapped by the Location "externalId" field.
Here is a simplified code sample of my entities and their relation :
// Location.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity(repositoryClass="App\Repository\LocationRepository")
* #ORM\Table(name="Location")
*/
class Location extends Entity
{
/**
* #var integer
* #ORM\Column(type="integer", unique=true, nullable=true)
*/
protected $locationId;
/**
* #var integer
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer", nullable=false)
*/
protected $externalId;
/**
* #var Venue[]|Collection
* #ORM\OneToMany(targetEntity="App\Entity\Venue", mappedBy="locationExternalId", orphanRemoval=true, fetch="LAZY")
*/
protected $venues;
/**
* Location constructor.
* #param array $data
*/
public function __construct(array $data)
{
$this->venues = new ArrayCollection;
$this->hydrate($data);
}
/**
* #return int
*/
public function getLocationId()
{
return $this->locationId;
}
/**
* #param int $locationId
* #return $this
*/
public function setLocationId($locationId)
{
$this->locationId = $locationId;
return $this;
}
/**
* #return Venue[]|Collection
*/
public function getVenues()
{
return $this->venues;
}
/**
* #param Venue[]|Collection $venues
* #return $this
*/
public function setVenues($venues)
{
$this->venues = $venues;
return $this;
}
}
// Venue.php
namespace App\Entity;
use App\Entity\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity(repositoryClass="App\Repository\VenueRepository")
* #ORM\Table(name="Venue", indexes={#ORM\Index(name="IDX_Venue", columns={"location_id"})})
*/
class Venue extends Entity
{
/**
* #var integer
* #ORM\Column(type="integer", unique=true, nullable=true)
*/
protected $venueId;
/**
* #var integer
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer", nullable=false)
*/
protected $externalId;
/**
* #var Location
* #ORM\ManyToOne(targetEntity="App\Entity\Location", inversedBy="venues")
* #ORM\JoinColumn(name="location_external_id", referencedColumnName="external_id", nullable=true)
*/
protected $locationExternalId;
/**
* Venue constructor.
* #param array $data
*/
public function __construct(array $data)
{
$this->hydrate($data);
}
/**
* #return int
*/
public function getVenueId()
{
return $this->venueId;
}
/**
* #param int $venueId
* #return $this
*/
public function setVenueId($venueId)
{
$this->venueId = $venueId;
return $this;
}
/**
* #return int
*/
public function getExternalId()
{
return $this->externalId;
}
/**
* #param int $externalId
* #return $this
*/
public function setExternalId($externalId)
{
$this->externalId = (int)$externalId;
return $this;
}
/**
* #return Location
*/
public function getLocationExternalId()
{
return $this->locationExternalId;
}
/**
* #param Location $locationExternalId
* #return $this
*/
public function setLocationExternalId($locationExternalId)
{
$this->locationExternalId = $locationExternalId;
return $this;
}
}
If I load a Location, Venues is not initialized, that's what is expected :
// Controller.php
use App\Entity\Basketball\Location;
use App\Entity\Basketball\Venue;
$location = $this->getDoctrine()->getRepository(Location::class)->findOneBy(['externalId' => 1]);
dump($location);
// Dump results
App\Entity\Location {#1438 ▼ #locationId: 1644
#externalId: 1
#venues: Doctrine\ORM\PersistentCollection {#1450 ▼
-snapshot: []
-owner: App\Entity\Location {#1438}
-association: array:15 [ …15]
-em: Doctrine\ORM\EntityManager {#75 …11}
-backRefFieldName: "locationExternalId"
-typeClass: Doctrine\ORM\Mapping\ClassMetadata {#1441 …}
-isDirty: false
#collection: Doctrine\Common\Collections\ArrayCollection {#1700 ▶}
#initialized: false
But it should by calling the getter, and it's not working as expected
// Controller.php
dump($location->getVenues());
// Dump results
Doctrine\ORM\PersistentCollection {#1450 ▼
-snapshot: []
-owner: App\Entity\Location {#1438 ▶}
-association: array:15 [ …15]
-em: Doctrine\ORM\EntityManager {#75 …11}
-backRefFieldName: "locationExternalId"
-typeClass: Doctrine\ORM\Mapping\ClassMetadata {#1441 …}
-isDirty: false
#collection: Doctrine\Common\Collections\ArrayCollection {#1700 ▼
-elements: []
}
#initialized: false
}
Environment
Symfony v4.4.7
Doctrine v2.7 ("doctrine/doctrine-fixtures-bundle":
"^3.3")
By specifying "fetch=EAGER", it works, but I don't want to...
Any idea? What should I do to initialize my collection?
Edit
Thanks to this Github issue I found a workaround by initializing the collection inside the getter but still; there should be a way to do it automatically :
public function getVenues()
{
$this->venues->initialize();
return $this->venues;
}
Does it really need to you? For initializing collection you need to call some method of this collection. If you are using JMSSerializer or Symfony Serializer you can just return the serialized data, serializers do all job for you, because they call toArray method, that initialize your collection.
I want to use Product and Price classes with one-to-many references. This is my Product class.
/**
* #ApiResource
*
* #Document
*/
class Product
{
/**
* #ODM\Id(strategy="INCREMENT", type="integer")
*/
private $id;
/**
* #ODM\Field(type="string")
* #Assert\NotBlank
*/
public $name;
/**
* #ODM\ReferenceMany(targetDocument=Price::class, mappedBy="product", cascade={"all"}, storeAs="id")
*/
public $prices ;
public function __construct()
{
$this->prices = new ArrayCollection();
}
//getter and setter of id...
}
This is Price class
/**
* #ApiResource
*
* #ODM\Document
*/
class Price
{
/**
* #ODM\Id(strategy="INCREMENT", type="integer")
*/
private $id;
/**
* #ODM\Field(type="float")
* #Assert\NotBlank
* #Assert\Range(min=0, minMessage="The price must be superior to 0.")
* #Assert\Type(type="float")
*/
public $price;
/**
* #Assert\Type(type="integer")
*/
private $discount;
/**
* #ODM\ReferenceOne(targetDocument=Product::class, inversedBy="prices", storeAs="id")
*/
public $product;
I can put and get Price with id=1 but when I want to put Product in swagger ui I use this reference.
{
"name": "productno1",
"prices": [
"/api/prices/1/"
]
}
It gives 201. I can check the db it is stored. The name of the product is productno1 but price section is empty. Can anyone help about what is wrong?
I changed mappedby tag of prices variable in Product class with inversedby, then problem solved.
I have a ThirdPartyEntity from a third party bundle that, using a ThirdPartyEntityTrait, I link to MyEntity in my project.
Now, as the ThirdPartyEntity is not set a ApiResource nor as an ApiSubresource and as I don't have any serializaton group set on MyEntity, when I get MyEntity from ApiPlatform, it returns me something like this:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":22,
"a_property":"some value"
}
}
BUT IF I PUT a changed value for a_property with this body:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":22,
"a_property":"some NEW value to update"
}
}
I get a new third_party_entity to be created and get this response:
{
"#id":"/api/my_entities/17",
"#type":"MyEntity",
"id":17,
"third_party_entity": {
"id":23,
"a_property":"some NEW value to update"
}
}
SO, HOW CAN I UPDATE third_party_entity instead of creating it each time?
HERE THERE ARE THE INVOLVED CLASSES AND TRAITS
/**
* #ORM\Table(name="app_my_entities")
* #ORM\Entity()
* #ApiResource()
*/
class MyEntity
{
// !!!!!!!!!!!!!!!!!!
// This is the trait I use to link MyEntity
// with the entity from the third-party bundle
// !!!!!!!!!!!!!!!!!!
use ThirdPartyEntityTrait;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
...
}
And this is the ThirdPartyEntityTrait:
trait ThirdPartyEntityTrait
{
/**
* #ORM\OneToOne(targetEntity="Namespace\To\Bundle\Entity\ThirdPartyEntity", cascade={"all"})
* #ORM\JoinColumn(name="thirdPartyEntity", referencedColumnName="id")
*/
private $thirdPartyEntity;
/**
* #param thirdPartyEntity $thirdPartyEntity
*
* #return ThirdPartyEntity
*/
public function setThirdPartyEntity(thirdPartyEntity $thirdPartyEntity): ThirdPartyEntity
{
$this->thirdPartyEntity = $thirdPartyEntity;
/** #var ThirdPartyEntity $this */
return $this;
}
/**
* #return thirdPartyEntity
*/
public function getThirdPartyEntity(): ?thirdPartyEntity
{
return $this->thirdPartyEntity;
}
/**
* #return thirdPartyEntity
*/
public function removeThirdPartyEntity(): ?thirdPartyEntity
{
$thirdPartyEntity = $this->getThirdPartyEntity();
$this->thirdPartyEntity = null;
return $thirdPartyEntity;
}
}
As you can see, nothing more a property to save the relation and some accessors methods.
This is, instead, the linked Entity:
/**
* #ORM\Entity()
* #ORM\Table(name="third_party_entities")
*/
class ThirdPartyEntity
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #ORM\Column(name="aProperty", type="string", nullable=true)
*/
private $aProperty;
public function getId()
{
return $this->id;
}
public function getAProperty()
{
return $this->aProperty;
}
public function setAProperty($aProperty)
{
$this->aProperty = $aProperty;
return $this;
}
}
This question is cross-posted also on GitHub.
The solution was pretty simple: use another config method!
Practically, it is possible to mix configuration types and so, it is possible to use the annotations along with the yaml configuration.
Given this, it is sufficient to create a new config file in config/api_platform/third_party_entity.yaml.
In it put the configuration required to map the entity from the third party bundle:
resources:
App\Entity\MyEntity:
properties:
remote:
subresource:
resourceClass: 'Third\Party\Bundle\TheBundle\Entity\ThirdPartyEntity'
Third\Party\Bundle\TheBundle\Entity\ThirdPartyEntity:
This way it is possible to configure as subresource the entity from the third party bundle to which we don't have access with annotations.
I've extended the Product model from CoreBundle (v1.0.0-alpha) and I want to change the behavior of the fixtures based on this new model. Keeping in mind that CoreBundle\Fixture\Factory\ProductExampleFactory is final, I am looking for a way to extend the fixtures so I don't have to rewrite the whole class and the whole "default" suite.
AppBundle\Entity\Product
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Product as BaseProduct;
/**
* Product
*
* #author leogout
*
* #ORM\Table(name="sylius_product")
* #ORM\Entity
*/
class Product extends BaseProduct
{
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="Package", mappedBy="component")
*/
protected $packages;
/**
* #var boolean
*
* #ORM\Column(type="boolean")
*/
protected $exposed;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="Customization", mappedBy="product")
* #ORM\JoinColumn(name="customization_id", referencedColumnName="id")
*/
protected $customizations;
/**
* Product constructor.
*/
public function __construct()
{
parent::__construct();
$this->packages = new ArrayCollection();
$this->customizations = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set exposed
*
* #param boolean $exposed
* #return Product
*/
public function setExposed($exposed)
{
$this->exposed = $exposed;
return $this;
}
/**
* Get exposed
*
* #return boolean
*/
public function getExposed()
{
return $this->exposed;
}
/**
* Add packages
*
* #param Package $packages
* #return Product
*/
public function addPackage(Package $packages)
{
$this->packages[] = $packages;
return $this;
}
/**
* Remove packages
*
* #param Package $packages
*/
public function removePackage(Package $packages)
{
$this->packages->removeElement($packages);
}
/**
* Get packages
*
* #return ArrayCollection
*/
public function getPackages()
{
return $this->packages;
}
/**
* Add customizations
*
* #param Customization $customizations
* #return Product
*/
public function addCustomization(Customization $customizations)
{
$this->customizations[] = $customizations;
return $this;
}
/**
* Remove customizations
*
* #param Customization $customizations
*/
public function removeCustomization(Customization $customizations)
{
$this->customizations->removeElement($customizations);
}
/**
* Get customizations
*
* #return ArrayCollection
*/
public function getCustomizations()
{
return $this->customizations;
}
}
Thanks in advance !
EDIT :
After some digging, I saw that I needed to code a whole new fixture with a new ProductFixture, a new ProductExampleFactory and a new MyCustomProductFixture on top of that with their own config files which is not ideal... Do you have a better solution ?
Hey I have two bundles in my symfony2 project. one is Bundle and the other one is PatentBundle.
My app/config/route.yml file is
MunichInnovationGroupPatentBundle:
resource: "#MunichInnovationGroupPatentBundle/Controller/"
type: annotation
prefix: /
defaults: { _controller: "MunichInnovationGroupPatentBundle:Default:index" }
MunichInnovationGroupBundle:
resource: "#MunichInnovationGroupBundle/Controller/"
type: annotation
prefix: /v1
defaults: { _controller: "MunichInnovationGroupBundle:Patent:index" }
login_check:
pattern: /login_check
logout:
pattern: /logout
inside my controller i have
<?php
namespace MunichInnovationGroup\PatentBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use JMS\SecurityExtraPatentBundle\Annotation\Secure;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Security\Core\SecurityContext;
use MunichInnovationGroup\PatentBundle\Entity\Log;
use MunichInnovationGroup\PatentBundle\Entity\UserPatent;
use MunichInnovationGroup\PatentBundle\Entity\PmPortfolios;
use MunichInnovationGroup\PatentBundle\Entity\UmUsers;
use MunichInnovationGroup\PatentBundle\Entity\PmPatentgroups;
use MunichInnovationGroup\PatentBundle\Form\PortfolioType;
use MunichInnovationGroup\PatentBundle\Util\SecurityHelper;
use Exception;
/**
* Portfolio controller.
* #Route("/portfolio")
*/
class PortfolioController extends Controller {
/**
* Index action.
*
* #Route("/", name="v2_pm_portfolio")
* #Template("MunichInnovationGroupPatentBundle:Portfolio:index.html.twig")
*/
public function indexAction(Request $request) {
$portfolios = $this->getDoctrine()
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
->findBy(array('user' => '$user_id'));
// rest of the method
}
Edit:
My Entity Class
<?php
namespace MunichInnovationGroup\PatentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MunichInnovationGroup\PatentBundle\Entity\PmPortfolios
*
* #ORM\Table(name="pm_portfolios")
* #ORM\Entity
*/
class PmPortfolios
{
/**
* #var string $id
*
* #ORM\Column(name="id", type="string", length=36, nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="UUID")
*/
private $id;
/**
* #var string $portfolioName
*
* #ORM\Column(name="portfolio_name", type="string", length=255, nullable=false)
*/
private $portfolioName;
/**
* #var text $description
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var string $permalink
*
* #ORM\Column(name="permalink", type="string", length=255, nullable=false)
*/
private $permalink;
/**
* #var string $sharingCode
*
* #ORM\Column(name="sharing_code", type="string", length=255, nullable=false)
*/
private $sharingCode;
/**
* #var boolean $shared
*
* #ORM\Column(name="shared", type="boolean", nullable=false)
*/
private $shared;
/**
* #var integer $sharedPortfolioCalls
*
* #ORM\Column(name="shared_portfolio_calls", type="integer", nullable=true)
*/
private $sharedPortfolioCalls;
/**
* #var boolean $isDefault
*
* #ORM\Column(name="is_default", type="boolean", nullable=false)
*/
private $isDefault;
/**
* #var UmUsers
*
* #ORM\ManyToOne(targetEntity="UmUsers")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* Get id
*
* #return string
*/
public function getId()
{
return $this->id;
}
/**
* Set portfolioName
*
* #param string $portfolioName
*/
public function setPortfolioName($portfolioName)
{
$this->portfolioName = $portfolioName;
}
/**
* Get portfolioName
*
* #return string
*/
public function getPortfolioName()
{
return $this->portfolioName;
}
/**
* Set description
*
* #param text $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* #return text
*/
public function getDescription()
{
return $this->description;
}
/**
* Set permalink
*
* #param string $permalink
*/
public function setPermalink($permalink)
{
$this->permalink = $permalink;
}
/**
* Get permalink
*
* #return string
*/
public function getPermalink()
{
return $this->permalink;
}
/**
* Set sharingCode
*
* #param string $sharingCode
*/
public function setSharingCode($sharingCode)
{
$this->sharingCode = $sharingCode;
}
/**
* Get sharingCode
*
* #return string
*/
public function getSharingCode()
{
return $this->sharingCode;
}
/**
* Set shared
*
* #param boolean $shared
*/
public function setShared($shared)
{
$this->shared = $shared;
}
/**
* Get shared
*
* #return boolean
*/
public function getShared()
{
return $this->shared;
}
/**
* Set sharedPortfolioCalls
*
* #param integer $sharedPortfolioCalls
*/
public function setSharedPortfolioCalls($sharedPortfolioCalls)
{
$this->sharedPortfolioCalls = $sharedPortfolioCalls;
}
/**
* Get sharedPortfolioCalls
*
* #return integer
*/
public function getSharedPortfolioCalls()
{
return $this->sharedPortfolioCalls;
}
/**
* Set isDefault
*
* #param boolean $isDefault
*/
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
}
/**
* Get isDefault
*
* #return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set user
*
* #param MunichInnovationGroup\PatentBundle\Entity\UmUsers $user
*/
public function setUser(\MunichInnovationGroup\PatentBundle\Entity\UmUsers $user)
{
$this->user = $user;
}
/**
* Get user
*
* #return MunichInnovationGroup\PatentBundle\Entity\UmUsers
*/
public function getUser()
{
return $this->user;
}
}
My bundle main class: MunichInnovationGroupPatentBundle.php
<?php
namespace MunichInnovationGroup\PatentBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MunichInnovationGroupPatentBundle extends Bundle
{
}
when i try to load localhost/web/app_dev.php/portfolio
It says
Unknown Entity namespace alias 'MunichInnovationGroupPatentBundle'.
I am unable to figure out this error
please help me if anyone has any idea I googled it a lot :(
Thanks in advance
500 Internal Server Error - ORMException
Please, check your config.yml.
Reviewed in section mappings of entity_managers.
You should have something like MunichInnovationGroupPatentBundle: ~
That is:
doctrine:
orm:
entity_managers:
defaults:
mappings:
MunichInnovationGroupPatentBundle: ~
In my case I was missing namespace name in the security.yml under providers
I had:
entity: { class: AdministratorBundle:AdminUser }
and needed to have:
entity: { class: NamespaceAdministratorBundle:AdminUser }
If you use 2 or more entity managers -- you need to specify manager also
getManager('YourManager')
$repository =
$this->getDoctrine()
->getManager('YourManager')
->getRepository('YourBundle:YourEntity');
Check you bundle logical name (MunichInnovationGroupPatentBundle). Bundle logical name is name of main class of your bundle, e.g. JobsBundle
and provide your entity sourcecode.
Documentation here states you can use the string 'MunichInnovationGroupPatentBundle:PmPortfolios' as shortcut to 'MunichInnovationGroupPatentBundle\Entity\PmPortfolios' as long as your entity lives under the Entity namespace of your bundle.
Your bundle is MunichInnovationGroupBundle so instead of
->getRepository('MunichInnovationGroupPatentBundle:PmPortfolios')
use
->getRepository('MunichInnovationGroupPatentBundle\Entity\PmPortfolios')
Try being more explicit in your config.yml file by adding some fields:
orm:
...
mappings:
MunichInnovationGroupPatentBundle:
type: annotation
dir: "MunichInnovationGroupPatentBundle/Controller"
is_bundle: true
prefix: MunichInnovationGroup\PatentBundle
alias: MunichInnovationGroupPatentBundle
[more mappings..]
Please, check your config.yml + AppKernel.php
config.yml must be
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
or replace auto_mapping with
mappings:
StoreShopBundle: ~
for more, check this: https://stackoverflow.com/a/37652091/5809937
in AppKernel.php
don't forget to check if bundle is activated:
new MunichInnovationGroup\PatentBundle\MunichInnovationGroupPatentBundle(),
I had this when tried to use bandle name without core folder name. It was in config/security.yml
Folder structure in my case is the next src/Dp/UserBundle/....
I changed this
`providers:
main:
entity: { class: UserBundle:User, property: username }`
to this
`providers:
main:
entity: { class: DpUserBundle:User, property: username }`
So copy name of unknown Entity name and search each entries in project, check - they have to be with folder prefix (Dp in my case)
As at Symfony version 2.3.7, I used NameofCompanySomethingBundle:EntityRequired e.g. AcmeBlogBundle:User and it works.
auto-mapping: true (default) was used under orm: in config.yml.
This error will occur if you use multiple entity managers and you do not specify the entity manager in your controller function.
$em = $this->get('doctrine.orm.//your_entity_manager_name_here//_entity_manager');
$dql = "SELECT ...";
$query = $em->createQuery($dql);
this worked for me.
open your app\config.yml, must be
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
replace to
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
MunichInnovationGroupPatentBundle: ~