DDC-1042: "LEFT JOIN ... WITH" issues #1300

Closed
opened 2026-01-22 13:08:59 +01:00 by admin · 5 comments
Owner

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.

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.
admin added the Bug label 2026-01-22 13:08:59 +01:00
admin closed this issue 2026-01-22 13:09:00 +01:00
Author
Owner

@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): 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.
Author
Owner

@doctrinebot commented on GitHub (Feb 25, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Feb 25, 2011): Issue was closed with resolution "Invalid"
Author
Owner

@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 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).
Author
Owner

@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 @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.
Author
Owner

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

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1300