diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 8a8c1786..689ba0f1 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -55,9 +55,6 @@ class ActiveQuery extends Component implements ISqlBuilder */ public function __construct($model, $config = []) { - if (!is_object($model)) { - $model = Snowflake::createObject($model); - } $this->modelClass = $model; $this->builder = SqlBuilder::builder($this); @@ -131,6 +128,7 @@ class ActiveQuery extends Component implements ISqlBuilder * @param $sql * @param array $params * @return mixed + * @throws Exception */ public function execute($sql, $params = []): Command { @@ -148,8 +146,7 @@ class ActiveQuery extends Component implements ISqlBuilder if (empty($data)) { return NULL; } - $newModel = $this->modelClass; - $newModel = $this->populate($newModel, $data); + $newModel = $this->modelClass::populate($data); if ($this->asArray) { return $newModel->toArray(); } diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index d43b192e..2c6f1c72 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -16,6 +16,7 @@ use Database\ActiveRecord; use Exception; use JetBrains\PhpStorm\Pure; use Snowflake\Abstracts\Component; +use Snowflake\Snowflake; use Traversable; /** @@ -53,11 +54,6 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat { $this->_item = $array; $this->query = $query; - - if (!is_object($model)) { - $model = $model::populate([]); - $model->setIsCreate(false); - } $this->model = $model; parent::__construct([]); @@ -146,12 +142,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat return $this->_item[$offset]; } - $model = clone $this->getModel(); - $model = $model->setAttributes($this->_item[$offset]); - $model->setIsCreate(false); - $model->refresh(); - - return $model; + return $this->model::populate($this->_item[$offset]); } /** diff --git a/Database/Base/CollectionIterator.php b/Database/Base/CollectionIterator.php index ebb1d718..dd6a3439 100644 --- a/Database/Base/CollectionIterator.php +++ b/Database/Base/CollectionIterator.php @@ -56,11 +56,7 @@ class CollectionIterator extends \ArrayIterator */ protected function newModel($current): ActiveRecord { - $model = clone $this->model; - $model->setAttributes($current); - $model->setIsCreate(false); - $model->refresh(); - return $model; + return $this->model::populate($current); }