DDC-2420: [GH-656] [DDC-2235] Fix for using a LEFT JOIN onto an entity with single table inheritance #3035

Open
opened 2026-01-22 14:10:28 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 28, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of tarnfeld:

Url: https://github.com/doctrine/doctrine2/pull/656

Message:

Possible fix for the bug DDC-2235. I'd love to hear some opinions on whether this is the right way to go about this issue. I'm not particularly familiar with the internals of doctrine so there may be a better solution.


The issue is when using DQL to perform a left join on an entity using single
table inheritance, doctrine tries to insert an IN() predicate into the WHERE
clause for all of the discriminator values. That makes sense and is valid, so
it would be wrong to remove that behaviour.

However when using a left join having an IN() in the main where clause makes
the LEFT JOIN pretty much useless, as it implicitly creates a WHERE NOT NULL
clause. This commit attempts to fix that by including an OR IS NULL in the
query if the join is a LEFT JOIN.

I've added some regression tests to ensure this bug never creeps back in. They fail on master (highlighting the bug) and pass after these commits have been applied. I've also included a couple of other queries as tests to be sure only this one case has been affected.

Originally created by @doctrinebot on GitHub (Apr 28, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of tarnfeld: Url: https://github.com/doctrine/doctrine2/pull/656 Message: Possible fix for the bug [DDC-2235](http://www.doctrine-project.org/jira/browse/DDC-2235). I'd love to hear some opinions on whether this is the right way to go about this issue. I'm not particularly familiar with the internals of doctrine so there may be a better solution. --- The issue is when using DQL to perform a left join on an entity using single table inheritance, doctrine tries to insert an `IN()` predicate into the `WHERE` clause for all of the discriminator values. That makes sense and is valid, so it would be wrong to remove that behaviour. However when using a **left** join having an `IN()` in the main where clause makes the `LEFT JOIN` pretty much useless, as it implicitly creates a `WHERE NOT NULL` clause. This commit attempts to fix that by including an `OR IS NULL` in the query if the join is a `LEFT JOIN`. I've added some regression tests to ensure this bug never creeps back in. They fail on master (highlighting the bug) and pass after these commits have been applied. I've also included a couple of other queries as tests to be sure only this one case has been affected.
admin added the Bug label 2026-01-22 14:10:28 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3035