mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2849: Multiple selects of same entity with different conditions on associations return the same set of associated entities #3556
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 (Dec 11, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user koubas:
When I execute multiple selects of the same entity, like these (pseudocode):
result1 = [ SELECT d,e FROM Department d LEFT JOIN d.employees e WITH e.type="manager" WHERE d.id=1 ]
result2 = [ SELECT d,e FROM Department d LEFT JOIN d.employees e WITH e.type="worker" WHERE d.id=1 ]
the resulting tree of entities could contain unexpected entities in association fields.
Because Doctrine's entity manager already has instance of Department entity with id 1, after the first select, the second result is the same instance. That is ok and it is also mentioned in docs. However, because of this, the "employees" association of that entity is populated with the same set of Employee entities (managers) in result1 and result2, even though the programmer would expect the association in second result to be populated with worker employees (i.e. she doesn't know somebody called the first query somewhere else in the app).
Is this a bug, or it's well known behavior and there is some best practice to overcome it?
@doctrinebot commented on GitHub (Dec 13, 2013):
Comment created by @beberlei:
This is a known issue that cannot be fixed. Its actually why using
WITHis not recommended and you should instead use an EXTRA LAZY collection and the Criteria API to filter for subsets.@doctrinebot commented on GitHub (Dec 13, 2013):
Issue was closed with resolution "Can't Fix"
@doctrinebot commented on GitHub (Dec 16, 2013):
Comment created by koubas:
It's not an issue only when using 'WITH', it happens even when I modify that queries: '... LEFT JOIN d.employees e WHERE e.type="manager" AND d.id=1'. Maybe the worst effect is not that I can't do more than one query with differently filtered association, but that I can't predict somebody did that before me somewhere else in code and I just get wrong result. Shouldn't it throw an exception, instead of silently returning wrong result?