is it possible to sort by the summation of relations' objects values? • Team has_many Players • Player.Points • Team::get()->sort(['PlayersPointsTotal' => 'ASC']);


I guess not out of the box, according to

Show 1 attachment(s)

Affected Version

Silverstripe 4.4.1


It's not possible to use the Database-abstraction features in the ORM to create DataLists that are sorted by aggregates. However you can filter by them.

Steps to Reproduce

Hava a many_many relation, like Team <-> Fan, then you can do:

Team::get()-&gt;filter('Fans.Count():GreaterThan', 10);
(get Teams with more than 10 Fans)

but you cannot do
Team::get()-&gt;sort('Fans.Count()', 'ASC');
(trying to get list sorted by number of Fans, but fails with database error - excecute command denied for routine Fans.Count)

Hide attachment content

you can sort on a callback that calculates the points. Would be a bottleneck if you have tons of teams.


ah, nice, thanks for the tip! I'll see how it handles the list that's there... we pair the list down quite a bit so it might be ok size wise


we've got some manipulation to do, but close to the same


I suppose I could create a csv in the same dir as the originating file that's blank


really what I'm going for is uploading a file to the asset directory... then have an action menu option to do the conversion... but that's step 2 of x lol


PHP interns... I use notepad ++... 😬 , here... try this...


IDE hints totally changed how I work once I switched, never going back... ever