10_ballov-1452 10_ballov-174 Параметр возврата нового заполненногоq из запроса собственного экземпляра в SqlModel::fetch().
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user