From 51b79ed1ea05dc706adc67978bc3fa7fafd66c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 8 Sep 2020 01:17:35 +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 | 11 ++++------- Database/Base/AbstractCollection.php | 4 +++- Database/Collection.php | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 273c59e2..94125f39 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -218,13 +218,10 @@ class ActiveQuery extends Component */ public function all() { - $data = $this->modelClass::getDb() - ->createCommand($this->queryBuilder()) - ->all(); - - $collect = new Collection($this); - $collect->setModel($this->modelClass); - $collect->setItems($data); + $collect = new Collection($this, + $this->modelClass::getDb()->createCommand($this->queryBuilder())->all() + , $this->modelClass + ); if ($this->asArray) { return $collect->toArray(); } diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index 34edb3c1..510247f8 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -37,11 +37,13 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat * * @param $query * @param array $array + * @param null $model */ - public function __construct($query, array $array = []) + public function __construct($query, array $array = [], $model = null) { $this->_item = $array; $this->query = $query; + $this->model = $model; parent::__construct([]); } diff --git a/Database/Collection.php b/Database/Collection.php index e2e4477a..accdc3ba 100644 --- a/Database/Collection.php +++ b/Database/Collection.php @@ -207,7 +207,7 @@ class Collection extends AbstractCollection } $_filters[] = $value; } - return new Collection($this->query, $_filters); + return new Collection($this->query, $_filters, $this->model); } /**