Often times, developers use the same filters against the same table to categorize records by one or more columns, such as getting members of a marketing department:
SELECT * from EMPLOYEES where department = 'marketing'
or getting people from a city:
SELECT * from PEOPLE where CITY = 'Chicago'
If you find yourself doing the same over and over, you can abstract this away into a scope:
after that, just indicate what scope you need:
You can combine multiple scopes in the same request. If you have multiple scopes defined on your model:
then you can combine these scopes:
The framework will combine the scope filters together as expected.
Combine scopes and conditions
Further filtering is possible to using the
where() method as usual:
All the normal mechanisms and behavior is still in place.
Scopes allow to abstract away mundane requests and make the code more readable.
How to comment
The comment section below is to discuss documentation on this page.
If you have an issue, or discover bug, please follow instructions on the Support page