[DDC-736] Nasty ordering issue with fetch-joins Created: 07/Aug/10  Updated: 10/Dec/10  Resolved: 13/Nov/10

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.0-BETA3
Fix Version/s: 2.0-RC1
Security Level: All

Type: Bug Priority: Critical
Reporter: Roman S. Borschel Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File ddc736-simplified.patch     Text File ddc736.patch     File DDC736Test.php    
Issue Links:
Reference
is referenced by DDC-915 Breaks with Fixing Identification Var... Resolved
is referenced by DDC-925 Breaks with Fixing Identification Var... Resolved

 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.



 Comments   
Comment by Roman S. Borschel [ 30/Aug/10 ]

Scheduling for RC1.

Comment by Tim Oram [ 15/Oct/10 ]

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.

Comment by Benjamin Eberlei [ 10/Nov/10 ]

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

Comment by Roman S. Borschel [ 12/Nov/10 ]

Attached simplified patch.

Comment by Benjamin Eberlei [ 13/Nov/10 ]

Fixed.

Comment by Mikko Hirvonen [ 07/Dec/10 ]

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.

Generated at Wed Jul 23 12:00:51 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.