Jira issue originally created by user legolas:
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.
* @ORM\OneToMany(targetEntity="Bugs", mappedBy="reporter",fetch="EAGER")
* @var Bugs
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 userid = 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 userid = 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 created by @ocramius:
[~legolas] are you actually using 2.0 or is this on a newer branch? (2.3?)
Comment created by legolas:
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 created by @beberlei:
Fixed and scheduled for 2.3.4
Issue was closed with resolution "Fixed"