[DDC-1757] DQL exception when building query with multiple from and join parts Created: 03/Apr/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: 2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Aigars Gedroics Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Attachments: File DDC1757Test.php     Text File patch-1757.patch    


Query builder creates bad DQL if multiple FROM and JOIN parts are used.

As example such query builder code

$qb->from('A', 'a')
  ->from('B', 'b')
  ->join('b.c', 'c')
  ->join('c.d', 'd');

will generate DQL

  FROM A a 
    INNER JOIN c.d d, 
  B b 
    INNER JOIN b.c c

but should generate this instead

  FROM A a,
  B b 
    INNER JOIN b.c c 
    INNER JOIN c.d d

The DQL parser raises exception

Doctrine\ORM\Query\QueryException: [Semantical Error] line 0, col 61 near '.d d, B': Error: Identification Variable c used in join path expression but was not defined before.

Comment by Aigars Gedroics [ 03/Apr/12 ]

The test case attached.
The problem is that for the relation c.d the query builder uses the first root entity as the master which makes it to be included before the join b.c.

Comment by Aigars Gedroics [ 03/Apr/12 ]

Dirty patch attached.

Comment by Benjamin Eberlei [ 27/May/12 ]

This was fixed through a PR some weeks ago.

Generated at Tue Dec 01 00:53:10 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.