Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Sorting with multiple columns randomly orders the columns specified in the array


Go to End


1180 Views

Avatar
doublecheese

Community Member, 5 Posts

15 August 2016 at 6:04pm

We have this in our code:

$items = $items->sort(array('LastActivity' => 'DESC', 'ActivityDate' => 'DESC', 'Date' => 'DESC', 'Created' => 'DESC'));

But the generated sql seems to always just put Activity Date first:

...
ORDER BY "ActivityDate" DESC, "LibraryItem"."LastActivity" DESC, "LibraryItem"."Date" DESC, "LibraryItem"."Created" DESC

How do we specify a column list in the sort() such that it respects the order that they are specified in?