Assume I've an entity, which references itself to map parent-child-relations
class Food
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMManyToOne(targetEntity="Food", inversedBy="foodChildren")
* @ORMJoinColumn(name="food_group_id", nullable=true)
*/
protected $foodGroup;
/**
* @ORMOneToMany(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()
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…