From 2f5b3abf4760e9d256b23446ecb041a454a98a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 19:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveQuery.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 0ad2f476..97ce555d 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -132,7 +132,10 @@ class ActiveQuery extends Component */ public function first() { - $data = $this->command($this->oneLimit()->adaptation())->one(); + $data = $this->modelClass::getDb() + ->createCommand($this->oneLimit()->queryBuilder()) + ->one(); + if (empty($data)) { return NULL; } @@ -215,7 +218,10 @@ class ActiveQuery extends Component */ public function all() { - $data = $this->command($this->adaptation())->all(); + $data = $this->modelClass::getDb() + ->createCommand($this->getBuild()->count($this)) + ->all(); + $collect = new Collection(); $collect->setModel($this->modelClass); if (empty($data) || !is_array($data)) { @@ -262,7 +268,9 @@ class ActiveQuery extends Component */ public function count() { - $data = $this->command($this->getBuild()->count($this))->one(); + $data = $this->modelClass::getDb() + ->createCommand($this->getBuild()->count($this)) + ->one(); if ($data && is_array($data)) { return (int)array_shift($data); } @@ -312,7 +320,9 @@ class ActiveQuery extends Component */ public function exists() { - return (bool)$this->command($this->adaptation())->fetchColumn(); + return (bool)$this->modelClass::getDb() + ->createCommand($this->queryBuilder()) + ->fetchColumn(); } /** @@ -321,7 +331,9 @@ class ActiveQuery extends Component */ public function deleteAll() { - return $this->command($this->getChange()->delete($this))->delete(); + return $this->modelClass::getDb() + ->createCommand($this->queryBuilder()) + ->delete(); } /** @@ -346,7 +358,7 @@ class ActiveQuery extends Component * @return string * @throws Exception */ - public function adaptation() + public function queryBuilder() { return $this->getBuild()->getQuery($this); }