muskie9

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

wmk

I guess not out of the box, according to https://github.com/silverstripe/silverstripe-framework/issues/9108

Show 1 attachment(s)
cloph

Affected Version

Silverstripe 4.4.1

Description

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
wmk

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

muskie9

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

muskie9

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

muskie9

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

muskie9

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

muskie9

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

muskie9

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