Sorting a list of data using a counted / aggregated column
Is it possible to sort the Datalist / ComponentSet dataset using calculated / virtual / aggregated col?
I have a DataList that contains events that have StartDate and EndDate. Now I want to sort the list by event duration (shortest to longest).
In SQL, I would do:
... ORDER BY DATEDIFF(EndDate, StartDate) ASC
How to do it with silverstripe ORM
$list = Event::get()->sort('????');
An extra column containing the new field duration and populating that field in onAfterWrite-hooks is not preferred.
Is it possible?
Robert
+3
source to share
3 answers