Contents
- Basic Concepts
- Models and Schemas
- Column Types
- Collections
- Filtering
- Groups
- Inverting Filters (not)
- Back references
- Advanced Filters
- Creating Your Own Filter
- Default Filters
- Relationships
- Data Decorators
- Data Storage and Typing
- Repositories
- Data Typing and Data Transforms
- Advanced Techniques
- Joins and Intersections
- Aggregates
- Model Events
- Custard Commands
- Updating DocBlock comments
- Migrating Schemas
- Common Patterns and Anti-Patterns
- Inter-Model Strategies
Filter By Default
Overriding the Model::find() function allows for a model to be filtered and sorted by default. This allows you to make it difficult to create a collection with important security filters in place.
For example, the following will ensure that only records without a delete flag set will be returned in collections by default.
public static function find(...$filters)
{
$filters[] = new Equals( 'DeletedFlag', false );
return parent::find(...$filter );
}
Note that while this cause collections returned by
findorallto be filtered by default, there is nothing to stop someone from removing the filter (e.g. withreplaceFilter()) so this is an incomplete approach to use as a method of data partitioning as it's easy to make a mistake that removes the data partitioning filter.