From 6d0ee5edab1e50a8dad1ba42369529407828656b Mon Sep 17 00:00:00 2001 From: Tom Benner Date: Thu, 1 Mar 2012 17:38:25 -0500 Subject: [PATCH] Adding dynamic find_one_by_* methods to MvcModel --- core/models/mvc_model.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/models/mvc_model.php b/core/models/mvc_model.php index f6dd433..09a6f66 100644 --- a/core/models/mvc_model.php +++ b/core/models/mvc_model.php @@ -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;