DDC-812: DQL hydration of joined objects skipped when main instance already present in entity manager #5330

Closed
doctrinebot opened this Issue Sep 21, 2010 · 3 comments

1 participant

@doctrinebot

Jira issue originally created by user dennis.verspuij:

I do the following:

$author1 = $em->find('Author', 1);

$author1again = $em
  ->createQuery(
    'SELECT A, B '.
    'FROM Author A '.
    'INNER JOIN A.Books B '.
   'WHERE A.ID = 1'
  )
  ->getSingleResult();

the Books collection is not hydrated because the author instance was already
hydrated when populating $author1. This means when I call
count($author1->getBooks()) a third query is executed to fetch the Books again.

The result is even more problematic when adding a WITH clause to the
INNER JOIN, in that case one would expect the Books collection to only
contain the books matching matching that criteria.

The result is expected when commenting out the $author1 =... line, thus when
the author does not already exist in the entity manager.

I'm sorry I can't produce a test case right now.

@doctrinebot

Comment created by @beberlei:

fix formatting

@doctrinebot

Comment created by romanb:

Fixed in master. Note that your second case still "won't work" from your point of view. If the collection is already initialized it is not overridden. This is consistent with other behavior (what is in-memory is preserved). Fetch-joinining a collection and using WITH at the same time is not a nice thing to do since the meaning of the association is changed per-query. First $author->getBooks() means one thing (all books written by this author) and a few lines later something else (all books written by this author in the last 10 years or whatever). To get the desired result in your second case, that is, overriding the collection in-memory, set the REFRESH query hint. Note that this will change the meaning of Author#books though, as is always the case with fetch-join + WITH.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-RC1 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