Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1757

DQL exception when building query with multiple from and join parts

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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.
      
      1. DDC1757Test.php
        2 kB
        Aigars Gedroics
      2. patch-1757.patch
        2 kB
        Aigars Gedroics

        Activity

        Hide
        beberlei Benjamin Eberlei added a comment -

        This was fixed through a PR some weeks ago.

        Show
        beberlei Benjamin Eberlei added a comment - This was fixed through a PR some weeks ago.
        Hide
        gedrox Aigars Gedroics added a comment -

        Dirty patch attached.

        Show
        gedrox Aigars Gedroics added a comment - Dirty patch attached.
        Hide
        gedrox Aigars Gedroics added a comment -

        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.

        Show
        gedrox Aigars Gedroics added a comment - 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.

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            gedrox Aigars Gedroics
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: