silverstripe/sapphire — comment on commit b3c986b2d40a72ec4e9232b45e4a15f9d89b38bd
File: model/SQLQuery.php line 312
By sminnee:

I think that orderby should be stored as an array and not a string in the SQL query fragment, and imploded only when it's time to run the query. In particular, we should be making the internal data structure both distinct and amenable to easy manipulation.

For example, I suspect that an order by clause like this would break the reverse code: `ORDER BY implode("Title","AuthorID"), "Created" DESC`.

If this was stored like so, manipulation would be much easier:

array(
'implode("Title","AuthorID")' => 'asc',
'"Created"' => 'desc',
);

Of course, if you called `$datalist->orderby('implode("Title","AuthorID"), "Created" DESC')` we'd still need to make that work. The solution is a more expensive parser (we need to count the number of quotes and ignore any comma contained within unmatched quote pairs, or go the whole hog and use PEG), but by discouraging the use of the above syntax, we can revert to that expensive parse only in exceptional circumstances.