mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: Add documentation for aggregate filters (#6796)
* MINOR: Add documentation for aggregate filters * Update 01_Data_Model_and_ORM.md * Update 01_Data_Model_and_ORM.md
This commit is contained in:
parent
9b1baa9503
commit
fdd9ad6dbc
@ -390,6 +390,23 @@ It is also often useful to filter by all rows with either empty or null for a gi
|
||||
// ... WHERE "FirstName" == '' OR "FirstName" IS NULL
|
||||
// Returns rows with FirstName which is either empty or null
|
||||
|
||||
### Filtering by aggregates
|
||||
|
||||
You can use aggregate expressions in your filters, as well.
|
||||
|
||||
```php
|
||||
// get the teams that have more than 10 players
|
||||
$teams = Team::get()->filter('Players.Count():GreaterThan', 10);
|
||||
|
||||
// get the teams with at least one player who has scored 5 or more points
|
||||
$teams = Team::get()->filter('Players.Min(PointsScored):GreaterThanOrEqual', 5);
|
||||
|
||||
// get the teams with players who are averaging more than 15 points
|
||||
$teams = Team::get()->filter('Players.Avg(PointsScored):GreaterThan', 15);
|
||||
|
||||
// get the teams whose players have scored less than 300 points combined
|
||||
$teams = Team::get()->filter('Players.Sum(PointsScored):LessThan', 300);
|
||||
```
|
||||
|
||||
### filterByCallback
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user