mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-24 18:51:27 +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);
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user