Created
May 6, 2020 03:36
-
-
Save muskie9/8b4d5c4e168c19818b0fa0bfce33fab0 to your computer and use it in GitHub Desktop.
Sorting object by summation of related objects that are filtered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo extends DataObject | |
{ | |
private static $has_many = [ | |
'Bars' => Bar::class, | |
]; | |
} | |
class Bar extends DataObject | |
{ | |
private static $db = [ | |
'Approved' => 'Boolean', | |
'Points' => 'Int', | |
]; | |
private static $has_one = [ | |
'Foo' => Foo::class, | |
]; | |
} | |
class Baz extends PageController | |
{ | |
public function getMyFoos() | |
{ | |
$foos = Foo::get(); | |
$foos = $foos->sort("Bars.Approved.SUM('Points')", 'ASC'); | |
return $foos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment