[DDC-2260] Partial DQL query doesn't respect given order of columns Created: 26/Jan/13 Updated: 27/Jan/13
|Project:||Doctrine 2 - ORM|
|Reporter:||Alexander Grimalovsky||Assignee:||Benjamin Eberlei|
When executing partial DQL queries it may be important to keep given order of columns e.g. for "pairs" hydrator when first column of a pair is used as a key and second - as value. For example query like this:
will expect "id" to be first in resulted set and "name" to be second and not vice versa.
However Doctrine parses this part of statement via iterating over fields mapping from entity's class metadata (as can be seen in Doctrine\ORM\Query\SqlWalker::walkSelectExpression()):
and hence given columns order preserving is not guaranteed.
|Comment by Marco Pivetta [ 26/Jan/13 ]|
What is the advantage in respecting the order given in the DQL query?
|Comment by Alexander Grimalovsky [ 27/Jan/13 ]|
Currently the only practical reason for it that I found is "pairs" hydrator. However it is, of course, possible to implement it without such change too.
Generally speaking this behavior (getting result set with same order of columns that was given in a query) is something that is feeling "natural" for operations with database since it is how you normally get results from SQL queries.
Maybe it will be enough to mention in documentation for Doctrine that given columns order is not guaranteed to be kept.
|Comment by Marco Pivetta [ 27/Jan/13 ]|
@Alexander Grimalovsky I don't think it's worth mentioning it. Also, including a fix for this is quite complex. If you prefer to document it, go for it!