From d8031c497b877f515e2709250a2f76745feabb75 Mon Sep 17 00:00:00 2001 From: Eduard Date: Thu, 9 Apr 2020 21:41:05 +0300 Subject: [PATCH] =?UTF-8?q?10=5Fballov-1452=2010=5Fballov-174=20=D0=9F?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=82=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BEq=20=D0=B8=D0=B7=20=D0=B7=D0=B0=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=B0=20=D1=81=D0=BE=D0=B1=D1=81=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=8D=D0=BA=D0=B7=D0=B5=D0=BC?= =?UTF-8?q?=D0=BF=D0=BB=D1=8F=D1=80=D0=B0=20=D0=B2=20SqlModel::fetch().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/SqlModel.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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;