Skip to content

Loading…

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

Open
doctrinebot opened this Issue · 0 comments

2 participants

@doctrinebot

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
@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.