diff --git a/Model/SqlModel.php b/Model/SqlModel.php index 5991557..32f1343 100644 --- a/Model/SqlModel.php +++ b/Model/SqlModel.php @@ -164,9 +164,10 @@ abstract class SqlModel extends Model * @param string $data Request * @param array $params Request parameters * @param CacheKey $cache_key Key for caching in + * @param bool $returnNewInstance Return the instance of this filled from query * @return mixed */ - protected function fetch($data, $params = array(), $cache_key = null) + protected function fetch($data, $params = array(), $cache_key = null, $returnFilledInstance = true) { if (!$cache_key || !$result = $cache_key->get()) { $result = $this->query($data, $params)->fetch(); @@ -175,19 +176,17 @@ abstract class SqlModel extends Model } } - $calledClassName = get_called_class(); - - if ($result) { - $orm = new $calledClassName; + if ($result && $returnFilledInstance) { + $instance = new $this; foreach (get_object_vars($result) as $key => $value) { if ($key == 'table') { $key = 'table_field'; } - $orm->$key = $value; + $instance->$key = $value; } - return $orm; + return $instance; } return $result;