From fdd9ad6dbccb1b5d56e62b6745b4478705e476ee Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Wed, 19 Apr 2017 15:44:00 +1200 Subject: [PATCH] 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 --- .../00_Model/01_Data_Model_and_ORM.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md b/docs/en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md index b6970ef63..7b64da534 100644 --- a/docs/en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md +++ b/docs/en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md @@ -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