j4mie/idiorm — pull request #177 by sergeylukin (2014-01-24 19:11:18+00:00)
Title: Add method that resets last SELECT statement conditions

My use case:

```php
class Locale {
private $loader;
private $language;
public function __construct( LocaleLoader $loader, $language ) {
$this->loader = $loader;
$this->language = $language;
}
public function get($term) {
return $this->loader->get_translation($term, $this->language);
}
}

interface LocaleLoader {
public function get_translation($language);
}

class LocaleDBLoader implements LocaleLoader {
private $model;
public function __construct( ORM $model ) {
$this->model = $model;
}
public function get_translation($term, $language = 'en') {
return $this->model
->reset_conditions()
->where('term', $term)
->find_one()
->translations()
->where('langauge', $language)
->find_one();
}
}

$loader = new LocaleDBLoader( Model::factory('Models\Term') );
$locale = new Locale( $loader, 'ca' );
echo 'In Catalan book is "' . $locale->get('book') . '" and pen is "' . $locale->get('pen') . '"';
```

Without `reset_conditions()` SELECT query adds conditions every time a method is called which results in wrong results.

Hopefully that makes sense.