DDC-1757: DQL exception when building query with multiple from and join parts #2211

Closed
opened 2026-01-22 13:44:45 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 3, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gedrox:

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.
Originally created by @doctrinebot on GitHub (Apr 3, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gedrox: 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. ```
admin added the Bug label 2026-01-22 13:44:45 +01:00
admin closed this issue 2026-01-22 13:44:49 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 3, 2012):

Comment created by gedrox:

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.

@doctrinebot commented on GitHub (Apr 3, 2012): Comment created by gedrox: 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.
Author
Owner

@doctrinebot commented on GitHub (Apr 3, 2012):

Comment created by gedrox:

Dirty patch attached.

@doctrinebot commented on GitHub (Apr 3, 2012): Comment created by gedrox: Dirty patch attached.
Author
Owner

@doctrinebot commented on GitHub (May 27, 2012):

Comment created by @beberlei:

This was fixed through a PR some weeks ago.

@doctrinebot commented on GitHub (May 27, 2012): Comment created by @beberlei: This was fixed through a PR some weeks ago.
Author
Owner

@doctrinebot commented on GitHub (May 27, 2012):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 27, 2012): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 2 attachments from Jira into https://gist.github.com/7b1b19046637f3a9f15e

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 2 attachments from Jira into https://gist.github.com/7b1b19046637f3a9f15e - [11176_DDC1757Test.php](https://gist.github.com/7b1b19046637f3a9f15e#file-11176_DDC1757Test-php) - [11177_patch-1757.patch](https://gist.github.com/7b1b19046637f3a9f15e#file-11177_patch-1757-patch)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2211