Commit c6e8f5a6 by Qiang Xue

Merge pull request #4543 from slavcodev/refactoring-query

Refactored ActiveQuery::one() to be consistent with all() creation
parents 8615296b fa8e5762
......@@ -242,24 +242,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface
{
$row = parent::one($db);
if ($row !== false) {
if ($this->asArray) {
$model = $row;
} else {
/* @var $class ActiveRecord */
$class = $this->modelClass;
$model = $class::instantiate($row);
$class::populateRecord($model, $row);
}
if (!empty($this->with)) {
$models = [$model];
$this->findWith($this->with, $models);
$model = $models[0];
}
if (!$this->asArray) {
$model->afterFind();
}
return $model;
$models = $this->prepareResult([$row]);
return reset($models) ?: null;
} else {
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment