Getting only ID from entity relations without fetching whole object in Doctrine
Assume I've an entity, which references itself to map parent-child-relationsclass Food{ /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** *...
View ArticleAnswer by Ken Hannel for Getting only ID from entity relations without...
I'm not sure if this is a performance issue and you're trying to limit queries but why not just do something like this in your getter (I'm assuming that's your Food entity using Doctrine ORM...
View ArticleAnswer by Noquepoaqui for Getting only ID from entity relations without...
You can use $em->getUnitOfWork()->getEntityIdentifier(...);to get id's without making joins.In your example it would be something like this:$em = $this->getDoctrine()->getManager();$food =...
View ArticleAnswer by Igor Pantović for Getting only ID from entity relations without...
Don't complicate your life, you can just do$food->getFoodGroup()->getId()This WILL NOT perform any additional query or trigger lazy load!This is because your $food->foodGroup is a proxy object...
View ArticleAnswer by Chadwick Meyer for Getting only ID from entity relations without...
You should be able to define the ID field, associate it with the ORM, and then create the getter for that field, and it should work./** * @ORM\ManyToOne(targetEntity="Food", inversedBy="foodChildren")...
View Article