[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
Environment:

Windows 8



 Description   

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.



 Comments   
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 ]

verified

Comment by Benjamin Eberlei [ 25/Jun/13 ]

Fixed and scheduled for 2.3.4

Comment by Koustubh Sinhal [ 25/Jun/13 ]

Thanx

Generated at Fri Oct 24 10:45:21 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.