Scope

Every query generated for the entity selection (directly or via relation) might pass through the defined scope. Scopes are used to define global query limits or/and filter entity by one of its relations.

Screenshot_76

In some cases, you can disable scope usage on root query to get access to unfiltered entities. Use $select->scope(null) to do that.

Since Cycle ORM version 1.5.0, the Cycle\ORM\Select\ConstrainInterface and the Cycle\ORM\Select::constrain() method marked as deprecated and will be removed in Cycle 2.0. Use the Cycle\ORM\Select\ScopeInterface and the Cycle\ORM\Select::scope() method instead.

Example

The following example demonstrates how to select entities which aren't marked as deleted:

php
use Cycle\ORM\Select;

class NotDeletedScope implements Select\ScopeInterface
{
    public function apply(Select\QueryBuilder $query)
    {
        $query->where('deleted_at', '=', null);
    }
}

Scope can be assigned to any entity via schema, in case of annotated extension:

php
/**
 * @Entity(scope="NotDeletedScope")
 */
class User
{
    // ...
}
Edit this page