[PR #656] [CLOSED] [DDC-2235] Fix for using a LEFT JOIN onto an entity with single table inheritance #8513

Open
opened 2026-01-22 16:00:15 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/656
Author: @tarnfeld
Created: 4/28/2013
Status: Closed

Base: masterHead: master


📝 Commits (7)

  • 6877610 Initial idea for fixing doctrine bug DDC-2235.
  • 615c25a Adjusted whitespace and added unit tests
  • 080c3e3 Spelling
  • 8ecc571 Moved the IN() predicate into the ON clause of the join
  • 1d86983 Small code cleanliness bits
  • 6db2ff0 Typo
  • 0d4d08c Coding standards

📊 Changes

2 files changed (+63 additions, -3 deletions)

View changed files

📝 lib/Doctrine/ORM/Query/SqlWalker.php (+14 -3)
📝 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php (+49 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/656 **Author:** [@tarnfeld](https://github.com/tarnfeld) **Created:** 4/28/2013 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (7) - [`6877610`](https://github.com/doctrine/orm/commit/68776106132418ef249f3f071b5c5f655a2f52b8) Initial idea for fixing doctrine bug DDC-2235. - [`615c25a`](https://github.com/doctrine/orm/commit/615c25a368a544cbdbfaf3947f76da4047a4a66a) Adjusted whitespace and added unit tests - [`080c3e3`](https://github.com/doctrine/orm/commit/080c3e3addc9e3b816c590456913c1fc088059df) Spelling - [`8ecc571`](https://github.com/doctrine/orm/commit/8ecc571accf05dad5dffc7e1f49fd64e25990186) Moved the `IN()` predicate into the `ON` clause of the join - [`1d86983`](https://github.com/doctrine/orm/commit/1d869835148c7b1d248f18d6dcd710d1fdce2ea8) Small code cleanliness bits - [`6db2ff0`](https://github.com/doctrine/orm/commit/6db2ff00f9420c8577583bd97fdea50392f2e8fc) Typo - [`0d4d08c`](https://github.com/doctrine/orm/commit/0d4d08c5d4cdab0fbe7c640ef8457d86073b769f) Coding standards ### 📊 Changes **2 files changed** (+63 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Query/SqlWalker.php` (+14 -3) 📝 `tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php` (+49 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:00:15 +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#8513