Quantcast
Channel: Getting only ID from entity relations without fetching whole object in Doctrine - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Getting only ID from entity relations without fetching whole object in Doctrine

$
0
0

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()?


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images