taylorotwell/eloquent — Issue #1: Filters for ORM queries
Author: kbanman
Created: 2012-01-25 08:53:49+00:00
State: open

This is an idea still forming in my head, based on a situation I just ran into, so bear with me as I try to explain:

In short, I think the `Query` objects used anywhere in Eloquent should be run through user-defined functions before firing them.
This would allow the developer to add constraints/modify the queries as necessary without messing with Eloquent's methods.

For example, in my app I needed to restrict all rows based on some WHEREs and join columns from another table. I figure this could be defined like so:

```php
public static function prepare_query(&$query, $type = 'select')
{
if ($type == 'select')
{
$query
->join('address', 'object_id', '=', 'customer_id')
->where('seq_num', '=', 0)
->raw_where('inactive_on IS NULL');
}
}
```

So `$type` could be one of 'select', 'insert', 'update', I suppose?

And this shouldn't need to change too much in Eloquent. Putting `static::prepare_query($model->query)` in the `public static function query($class)` declaration in Eloquent\Model would accomplish the bulk of it.

Anyhow, just throwing this on here for discussion sake. Any suggestions/corrections?