Skip to content

Model Configuration

scope()

scope() — returns void

Available in: model Category: Scope Functions

Defines a named query scope that can be chained onto finders. Scopes allow you to define reusable query fragments in the model config and compose them together.

NameTypeRequiredDefaultDescription
namestringyesThe name of the scope. This becomes a callable method on the model (e.g. model("User").active()).
wherestringnoA WHERE clause fragment to apply when this scope is used.
orderstringnoAn ORDER BY clause fragment to apply when this scope is used.
selectstringnoA SELECT clause override to apply when this scope is used.
includestringnoAssociations to include when this scope is used.
maxRowsnumericno0Maximum number of records to return when this scope is used.
handlerstringnoThe name of a method on this model that returns a struct of query arguments. Use for dynamic scopes that accept parameters. The method receives any arguments passed to the scope call.