diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 92ba42b2..273c59e2 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -222,7 +222,7 @@ class ActiveQuery extends Component ->createCommand($this->queryBuilder()) ->all(); - $collect = new Collection(); + $collect = new Collection($this); $collect->setModel($this->modelClass); $collect->setItems($data); if ($this->asArray) { diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index d5f44c36..cac9d7b0 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -27,14 +27,18 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat /** @var ActiveRecord */ protected $model; + protected $query; + /** * Collection constructor. * + * @param $query * @param array $array */ - public function __construct(array $array = []) + public function __construct($query, array $array = []) { $this->_item = $array; + $this->query = $query; parent::__construct([]); } diff --git a/Database/Collection.php b/Database/Collection.php index 0104d914..e2e4477a 100644 --- a/Database/Collection.php +++ b/Database/Collection.php @@ -187,13 +187,13 @@ class Collection extends AbstractCollection /** * @param array $condition - * @return Filters + * @return Collection * @throws */ public function filter(array $condition) { if (empty($condition)) { - return new Filters($this); + return $this; } $_filters = []; foreach ($this as $value) { @@ -207,7 +207,7 @@ class Collection extends AbstractCollection } $_filters[] = $value; } - return new Filters($_filters); + return new Collection($this->query, $_filters); } /** diff --git a/Database/Filters.php b/Database/Filters.php deleted file mode 100644 index c938fdb1..00000000 --- a/Database/Filters.php +++ /dev/null @@ -1,41 +0,0 @@ -_filters = $data; - } - - /** - * @return Collection - */ - public function get() - { - return new Collection($this->_filters); - } - - /** - * @return int - */ - public function count() - { - return count($this->_filters); - } - -}