Scopes
While you can create custom query methods by using custom
mappers, it is often desirable to create small named
bite-sized conditions for queries that can be chained together to create more
complex queries. Scopes are a convenient way to add custom methods to a
Spot\Query
object that serve this purpose.
Example Mapper With Scopes Defined
The scopes you define in the
scopes
method on your custom mapper will be
accessible from the Spot\Query
object.
Using Scopes in Queries
You can now use the free
and active
scopes as methods as soon as you have a
Spot\Query
object.
This will achieve the same result as chaining the where
conditions directly,
but using scopes have much greater readability and clarity: