|
@ -164,9 +164,10 @@ abstract class SqlModel extends Model |
|
|
* @param string $data Request |
|
|
* @param string $data Request |
|
|
* @param array $params Request parameters |
|
|
* @param array $params Request parameters |
|
|
* @param CacheKey $cache_key Key for caching in |
|
|
* @param CacheKey $cache_key Key for caching in |
|
|
|
|
|
* @param bool $returnNewInstance Return the instance of this filled from query |
|
|
* @return mixed |
|
|
* @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()) { |
|
|
if (!$cache_key || !$result = $cache_key->get()) { |
|
|
$result = $this->query($data, $params)->fetch(); |
|
|
$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) { |
|
|
foreach (get_object_vars($result) as $key => $value) { |
|
|
if ($key == 'table') { |
|
|
if ($key == 'table') { |
|
|
$key = 'table_field'; |
|
|
$key = 'table_field'; |
|
|
} |
|
|
} |
|
|
$orm->$key = $value; |
|
|
|
|
|
|
|
|
$instance->$key = $value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $orm; |
|
|
|
|
|
|
|
|
return $instance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return $result; |
|
|