Skip to content

Commit

Permalink
Adding dynamic find_one_by_* methods to MvcModel
Browse files Browse the repository at this point in the history
  • Loading branch information
tombenner committed Mar 1, 2012
1 parent a3c16df commit 6d0ee5e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/models/mvc_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,13 @@ protected function object_to_array($data) {
public function __call($method, $args) {
if (substr($method, 0, 8) == 'find_by_') {
$attribute = substr($method, 8);
if (isset($this->schema[$attribute])) {
$object = $this->find(array('conditions' => array($attribute => $args[0])));
return $object;
}
}
if (substr($method, 0, 12) == 'find_one_by_') {
$attribute = substr($method, 12);
if (isset($this->schema[$attribute])) {
$object = $this->find_one(array('conditions' => array($attribute => $args[0])));
return $object;
Expand Down

0 comments on commit 6d0ee5e

Please sign in to comment.