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

doctrinebot opened this Issue May 16, 2013 · 0 comments

2 participants


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:

    f0*.id AS id0, f0*.discr AS discr1 
    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 Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment