This commit is contained in:
2021-04-28 15:50:21 +08:00
parent 0c2a529910
commit 3a20af1d22
3 changed files with 5 additions and 21 deletions
+2 -5
View File
@@ -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();
}
+2 -11
View File
@@ -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]);
}
/**
+1 -5
View File
@@ -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);
}