Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 5 comments

2 participants

@doctrinebot

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.
@doctrinebot

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

Comment created by gedrox:

Dirty patch attached.

@doctrinebot

Comment created by @beberlei:

This was fixed through a PR some weeks ago.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.3 milestone
@doctrinebot doctrinebot closed this
@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.