Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-736

Nasty ordering issue with fetch-joins

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA3
    • Fix Version/s: 2.0-RC1
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Will not work correctly:

      select c, ca from Cart ca join ca.customer c

      Works correctly:

      select ca, c from Cart ca join ca.customer c

      In the first case the ordering of the DQL aliases causes associations to be skipped during hydration.

      1. ddc736.patch
        4 kB
        Benjamin Eberlei
      2. ddc736-simplified.patch
        4 kB
        Roman S. Borschel
      3. DDC736Test.php
        1 kB
        Roman S. Borschel

        Issue Links

          Activity

          Roman S. Borschel created issue -
          Hide
          Roman S. Borschel added a comment -

          Scheduling for RC1.

          Show
          Roman S. Borschel added a comment - Scheduling for RC1.
          Roman S. Borschel made changes -
          Field Original Value New Value
          Fix Version/s 2.0-RC1 [ 10091 ]
          Fix Version/s 2.0-BETA4 [ 10072 ]
          Description
          Will not work correctly:

          select c, ca from Cart ca join ca.customer c

          Works correctly:

          select ca, c from Cart ca join ca.customer c

          In the first case the ordering of the DQL aliases causes associations to be skipped during hydration.
          Will not work correctly:

          select c, ca from Cart ca join ca.customer c

          Works correctly:

          select ca, c from Cart ca join ca.customer c

          In the first case the ordering of the DQL aliases causes associations to be skipped during hydration.
          Hide
          Tim Oram added a comment -

          If anyone is getting issues with missing or incorrectly ordered relations it may be caused by this bug.

          Would it be possible to put a note in the documentation to ensure the order of the select clause must match that of the joins. I just spent 2 days trying to figure out why the data being returned was incorrect.

          Show
          Tim Oram added a comment - If anyone is getting issues with missing or incorrectly ordered relations it may be caused by this bug. Would it be possible to put a note in the documentation to ensure the order of the select clause must match that of the joins. I just spent 2 days trying to figure out why the data being returned was incorrect.
          Roman S. Borschel made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Roman S. Borschel made changes -
          Attachment DDC736Test.php [ 10846 ]
          Hide
          Benjamin Eberlei added a comment -

          Patch that solves this problem. What does it do?

          Two additional instance variables are needed, one for the order of the AliasIdentificationVariables and one for a IdentVariable => SelectExpression lookup map.

          Inside parse() a reordering is done right before the SQL Walkers are created. This is only done if there is more than one Identification variable in the select expressions, otherwise its not necessary.

          The reordering iterates in order of the alias identification variables, grabs the expression from the select expressions and appends it to them. This way it is guaranteed that the expressions are ordered correctly.

          SELECT a, b, c.foo, count(d.bar) FROM B b JOIN b.a a JOIN ...
          

          becomes:

          SELECT c.foo, count(d.bar), b, a FROM ...
          

          Roman do you think this is viable? See the patch for more details

          Show
          Benjamin Eberlei added a comment - Patch that solves this problem. What does it do? Two additional instance variables are needed, one for the order of the AliasIdentificationVariables and one for a IdentVariable => SelectExpression lookup map. Inside parse() a reordering is done right before the SQL Walkers are created. This is only done if there is more than one Identification variable in the select expressions, otherwise its not necessary. The reordering iterates in order of the alias identification variables, grabs the expression from the select expressions and appends it to them. This way it is guaranteed that the expressions are ordered correctly. SELECT a, b, c.foo, count(d.bar) FROM B b JOIN b.a a JOIN ... becomes: SELECT c.foo, count(d.bar), b, a FROM ... Roman do you think this is viable? See the patch for more details
          Benjamin Eberlei made changes -
          Attachment ddc736.patch [ 10857 ]
          Roman S. Borschel made changes -
          Attachment ddc736-simplified.patch [ 10860 ]
          Hide
          Roman S. Borschel added a comment -

          Attached simplified patch.

          Show
          Roman S. Borschel added a comment - Attached simplified patch.
          Hide
          Benjamin Eberlei added a comment -

          Fixed.

          Show
          Benjamin Eberlei added a comment - Fixed.
          Benjamin Eberlei made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
          Resolution Fixed [ 1 ]
          Hide
          Mikko Hirvonen added a comment -

          I think that this patch breaks modifying the select clause in custom tree walkers because walking the select clause will be done after the $_identVariableExpressions array is populated. Reordering the identification variables will then override the modified select clause.

          Show
          Mikko Hirvonen added a comment - I think that this patch breaks modifying the select clause in custom tree walkers because walking the select clause will be done after the $_identVariableExpressions array is populated. Reordering the identification variables will then override the modified select clause.
          Benjamin Eberlei made changes -
          Link This issue is referenced by DDC-915 [ DDC-915 ]
          Benjamin Eberlei made changes -
          Link This issue is referenced by DDC-925 [ DDC-925 ]
          Benjamin Eberlei made changes -
          Workflow jira [ 11738 ] jira-feedback [ 14530 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 14530 ] jira-feedback2 [ 16394 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 16394 ] jira-feedback3 [ 18647 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-736, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Roman S. Borschel
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: