DDC-2717: Join condition results in wrong SQL when used with CTI #3400

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

Originally created by @doctrinebot on GitHub (Oct 1, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user weph:

After upgrading from Doctrine 2.1.7 to 2.3.4 I discovered some unexpected behavior. When joining an entity which uses class table inheritance, the join condition will be put after the last left joined inherited table in the final SQL.

To give a concrete example: The Entity "Product" has multiple features. The "Feature" entity has two child tables "ExampleFeature1" and "ExampleFeature2".

The query builder looks like this:

$this->createQueryBuilder('p')
...
->leftJoin('p.features', 'f', 'WITH', 'f.someCriteria = 1')
...

The final SQL:

Doctrine 2.1.7:
SELECT ...
FROM products p
LEFT JOIN features f ON p.id = f.feature_id AND (f.some_criteria = 1)
LEFT JOIN example_feature1 f1 ON f.id = f1.id
LEFT JOIN example_feature1 f2 ON f.id = f2.id

Doctrine 2.3.4:
SELECT ...
FROM products p
LEFT JOIN features f ON p.id = f.feature_id
LEFT JOIN example_feature1 f1 ON f.id = f1.id
LEFT JOIN example_feature1 f2 ON f.id = f2.id AND (f.some_criteria = 1)

Originally created by @doctrinebot on GitHub (Oct 1, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user weph: After upgrading from Doctrine 2.1.7 to 2.3.4 I discovered some unexpected behavior. When joining an entity which uses class table inheritance, the join condition will be put after the last left joined inherited table in the final SQL. To give a concrete example: The Entity "Product" has multiple features. The "Feature" entity has two child tables "ExampleFeature1" and "ExampleFeature2". The query builder looks like this: $this->createQueryBuilder('p') ... ->leftJoin('p.features', 'f', 'WITH', 'f.someCriteria = 1') ... The final SQL: Doctrine 2.1.7: SELECT ... FROM products p LEFT JOIN features f ON p.id = f.feature_id AND (f.some_criteria = 1) LEFT JOIN example_feature1 f1 ON f.id = f1.id LEFT JOIN example_feature1 f2 ON f.id = f2.id Doctrine 2.3.4: SELECT ... FROM products p LEFT JOIN features f ON p.id = f.feature_id LEFT JOIN example_feature1 f1 ON f.id = f1.id LEFT JOIN example_feature1 f2 ON f.id = f2.id AND (f.some_criteria = 1)
admin added the Bug label 2026-01-22 14:19:14 +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#3400