mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 03:01:21 +08:00
Merge pull request #4543 from slavcodev/refactoring-query
Refactored ActiveQuery::one() to be consistent with all() creation
This commit is contained in:
@@ -242,24 +242,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
|||||||
{
|
{
|
||||||
$row = parent::one($db);
|
$row = parent::one($db);
|
||||||
if ($row !== false) {
|
if ($row !== false) {
|
||||||
if ($this->asArray) {
|
$models = $this->prepareResult([$row]);
|
||||||
$model = $row;
|
return reset($models) ?: null;
|
||||||
} 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;
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user