DDC-2530: Fetch eager in onetomany is not storing the collection resulting in same query being executed twice #3254

Closed
doctrinebot opened this Issue Jun 25, 2013 · 6 comments

2 participants

@doctrinebot

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.

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 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.

@doctrinebot

Comment created by @ocramius:

[~legolas] are you actually using 2.0 or is this on a newer branch? (2.3?)

@doctrinebot

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.

@doctrinebot

Comment created by @beberlei:

verified

@doctrinebot

Comment created by @beberlei:

Fixed and scheduled for 2.3.4

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by legolas:

Thanx

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.3.5 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment