[DDC-1314] DQL permits partial select using SQL Created: 02/Aug/11  Updated: 01/May/13  Resolved: 01/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.1
Fix Version/s: 3.0
Security Level: All

Type: Bug Priority: Minor
Reporter: Daniel Beresh Assignee: Benjamin Eberlei
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Mac OS X 10.6.7, PHP 5.3.5, Doctrine 2.1.0


Attachments: File IteratableHydratorTest.php    
Issue Links:
Duplicate
duplicates DDC-2133 Issue with Query::iterate and query m... Open

 Description   

The following code is not correct DQL and should (I think?) throw an error:

$query = $em->createQuery("SELECT g.id, g.name FROM Entity\Group g ORDER BY g.name ASC");

...to force the user to use SELECT partial g.

{id,name}

...

Instead, it causes very funny behaviour. eg. when iterating, objects are passed to the foreach in the following pattern:

$groups = $query->iterate();
foreach(...) {
1st time: $groups = array( [0] => object )
2nd time: $groups = array( [1] => object )
3rd time: $groups = array( [2] => object )
}



 Comments   
Comment by Benjamin Eberlei [ 06/Aug/11 ]

The incrementation of the return value is a bug, but SELECT g.id, g.name is valid DQL. You hydrate the values as scalars. What is funny is why it even returns an object in this case.

Comment by Guilherme Blanco [ 11/Dec/11 ]

Added failing test case.
Currently it is not easily doable without larger refactoring of Hydrators.
I'll keep this opened, but my 2 attempts failed.

Comment by Guilherme Blanco [ 23/Jun/12 ]

Scheduled for 3.0 since we're going to refactor the hydrators

Comment by Benjamin Eberlei [ 01/May/13 ]

Duplicate of DDC-2133 (better description)

Generated at Thu Apr 24 17:14:35 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.