mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1042: "LEFT JOIN ... WITH" issues #1300
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 (Feb 25, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user artefact2:
I have a very simple User/Message model, where a message can be addressed to several users, and can be read by several users. To achieve this, I use two unidirectional @ManyToMany relationships.
When I fetch the messages of one user, I also want to see if the message has been read by this user. I must then use an additional WITH condition when joining. The problem is that it doesn't always join correctly (see my test case).
I created a minimal test case here http://paste.pocoo.org/show/344314/ to help you identify the problem more easily.
@doctrinebot commented on GitHub (Feb 25, 2011):
Comment created by @beberlei:
This is expected (but admitetly weird) behavior, the entity is already in the identity map, which makes the WITH query not match and returning the other results.
You should not use WITH for this kind of logic, granted this can be documented much better.
@doctrinebot commented on GitHub (Feb 25, 2011):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Feb 26, 2011):
Comment created by artefact2:
Okay. But how I am supposed to query messages with their read status ? I can't omit the WITH clause, as it would fetch too many data (and would mess up LIMIT and OFFSET).
@doctrinebot commented on GitHub (Feb 26, 2011):
Comment created by @beberlei:
You can query the message first and then their read status. This would obviously be N+1 problem if you loop over the messages, but you seem to retrieve only exactly one message.
@doctrinebot commented on GitHub (Feb 26, 2011):
Comment created by artefact2:
I'm actually fetching multiple messages, and that's why I need to use LIMIT and OFFSET to query an exact number of messages. But thanks for your help, I'll see if there is another way.