[DDC-2530] Fetch eager in onetomany is not storing the collection resulting in same query being executed twice Created: 25/Jun/13  Updated: 30/Jun/13  Resolved: 25/Jun/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3.3
Fix Version/s: 2.3.5
Security Level: All

Type: Bug Priority: Major
Reporter: Koustubh Sinhal Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Windows 8


I have two entities Users and Bugs (A user can report multiple bugs) sharing bidirectional onetomany relation between them. On the inverse side of the relation I have put fetch = eager as given below.

class Users{
     * @ORM\OneToMany(targetEntity="Bugs", mappedBy="reporter",fetch="EAGER")
     * @var Bugs[]
     private $reportedBugs;

Now when I run this code:

$user = $em->find("ZC\Entity\Users", 7);

Firstly user entity is fetched from the user table with id = 7. Then it looks for the bugs associated with user_id = 7 in the bugs table. This seems to be the expected behavior where due to the eager fetch the related associations are automatically loaded. What seems to be the bug is, after this when the user's reported bugs are called, an unnecessary query is executed which again looks for the bugs in the bugs table related to the user_id = 7 and that is basically the same query as before. This is just a redundant query. So the eager fetch should have stored the associated bugs in the first call itself and the subsequent call to the reported bugs should just return the already fetched entities.

Comment by Marco Pivetta [ 25/Jun/13 ]

Koustubh Sinhal are you actually using 2.0 or is this on a newer branch? (2.3?)

Comment by Koustubh Sinhal [ 25/Jun/13 ]

Yup my bad, it is 2.3.3 version of doctrine. Atleast this is what i am seeing in the doctrine ORM version.php.

Comment by Benjamin Eberlei [ 25/Jun/13 ]


Comment by Benjamin Eberlei [ 25/Jun/13 ]

Fixed and scheduled for 2.3.4

Comment by Koustubh Sinhal [ 25/Jun/13 ]


Generated at Fri Oct 09 13:49:43 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.