mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1600: ORM loads an association without it being ever accessed #2009
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jan 15, 2012).
Originally assigned to: @guilhermeblanco on GitHub.
Jira issue originally created by user ambis:
03:14 < beberlei> Ambis, please report a bug on jira with details - this doesnt sound correct
I have a basic "Comment has an author" relation. Because I get each of my users from Redis cache directly using user's ID, the comment tracks both user as relation and also user's id like so:
(both access the same db field)
When I query only comments and access user only by getUserId() which returns the property 'userId' as seen on the mapping, my query logging shows that for each comment author there is a separate query to load it. I do not call getUser() at any point which would access the relation 'user' in the comment. Nothing within the comment entity itself accesses the relation. There seems to be no proxy generated out of the comment entity in my proxies folder.
I've had these problems before but I've always found out what was the reason behind this, but none of those seem to be the case this time. Unfortunately I have too much 2.2 code to roll back to 2.1 and test with that.
Edit:
The query itself is very simple:
CommentRepo->createQueryBuilder('comment')
->where('comment.anotherProperty = :somethingOrOther')
->setParameters(array(...))
->orderBy('comment.id', 'DESC')
->getQuery()
->getResult();
As always, there's lot more stuff to the query, but I've commented it out to that bare minimum when I still get this behavior.
Edit2:
I added to the query
->addSelect(array('comment_user'))
->join('comment.user', 'comment_user')
and of course the extra user queries went away.
I also added a die statement to the getUser() method (yes, above return ;) ) to see that it's really not called and it's not. Also re-checked the comment entity that nothing accesses the ->user property other that constructor and getUser().