Assume I've an entity, which references itself to map parent-child-relations
class Food
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Food", inversedBy="foodChildren")
* @ORM\JoinColumn(name="food_group_id", nullable=true)
*/
protected $foodGroup;
/**
* @ORM\OneToMany(targetEntity="Food", mappedBy="foodGroup", fetch="LAZY", cascade={"remove"})
*/
protected $foodChildren;
I have a use case where I want to get food_group_id
of an entity without getting full parent object from database. Using fetch="LAZY"
doesn't keep Doctrine from querying again. Is there a way to return only the ID when getting $food->getFoodGroup()
?