DDC-2452: Additional WITH condition in joins between JTI roots cause invalid SQL to be produced #3077

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

Originally created by @doctrinebot on GitHub (May 16, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user @ocramius:

Given a simple Joined Table Inheritance like following:

/****
 * @Entity @Table(name="foo") @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"foo" = "DDC2452Foo", "bar" = "DDC2452Bar"})
 */
class DDC2452Foo
{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    public $id;
}

/*** @Entity @Table(name="bar") **/
class DDC2452Bar extends DDC2452Foo
{
}```

Following DQL

```SELECT foo1 FROM DDC2452Foo foo1 JOIN DDC2452Foo foo2 WITH 1=1```

Will produce broken SQL:

```SELECT
    f0*.id AS id0, f0*.discr AS discr1 
FROM 
    foo f0_ 
LEFT JOIN bar b1_ 
    ON f0*.id = b1*.id 
LEFT JOIN foo f2_ 
LEFT JOIN bar b3_ 
    ON f2*.id = b3*.id 
    ON (1 = 1)```

(please note the duplicate `ON` in the SQL)

That is caused because of the SQL walker producing the JTI filter with already the `ON` clause in it.

That happens because the JTI join conditions are added in https://github.com/doctrine/doctrine2/blob/2.4.0-BETA2/lib/Doctrine/ORM/Query/SqlWalker.php#L823-L825 (`walkRangeVariableDeclaration`), while the additional defined `WITH` conditions are considered in `walkJoinAssociationDeclaration` later on.

Added a test case and fix at https://github.com/doctrine/doctrine2/pull/668
Originally created by @doctrinebot on GitHub (May 16, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user @ocramius: Given a simple Joined Table Inheritance like following: `````` /**** * @Entity @Table(name="foo") @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"foo" = "DDC2452Foo", "bar" = "DDC2452Bar"}) */ class DDC2452Foo { /*** @Id @Column(type="integer") @GeneratedValue **/ public $id; } /*** @Entity @Table(name="bar") **/ class DDC2452Bar extends DDC2452Foo { }``` Following DQL ```SELECT foo1 FROM DDC2452Foo foo1 JOIN DDC2452Foo foo2 WITH 1=1``` Will produce broken SQL: ```SELECT f0*.id AS id0, f0*.discr AS discr1 FROM foo f0_ LEFT JOIN bar b1_ ON f0*.id = b1*.id LEFT JOIN foo f2_ LEFT JOIN bar b3_ ON f2*.id = b3*.id ON (1 = 1)``` (please note the duplicate `ON` in the SQL) That is caused because of the SQL walker producing the JTI filter with already the `ON` clause in it. That happens because the JTI join conditions are added in https://github.com/doctrine/doctrine2/blob/2.4.0-BETA2/lib/Doctrine/ORM/Query/SqlWalker.php#L823-L825 (`walkRangeVariableDeclaration`), while the additional defined `WITH` conditions are considered in `walkJoinAssociationDeclaration` later on. Added a test case and fix at https://github.com/doctrine/doctrine2/pull/668 ``````
admin added the Bug label 2026-01-22 14:11:33 +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#3077