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.
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\ConstrainInterfaceand theCycle\ORM\Select::constrain()method marked as deprecated and will be removed in Cycle 2.0. Use theCycle\ORM\Select\ScopeInterfaceand theCycle\ORM\Select::scope()method instead.
The following example demonstrates how to select entities which aren't marked as deleted:
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:
/**
* @Entity(scope="NotDeletedScope")
*/
class User
{
// ...
}