Commit d1ebf655 by Qiang Xue

Fixed the issue that ActiveQuery::one() doesn't bring back related objects when asArray is true.

parent b2739b84
...@@ -124,10 +124,14 @@ class ActiveQuery extends Query ...@@ -124,10 +124,14 @@ class ActiveQuery extends Query
{ {
$command = $this->createCommand($db); $command = $this->createCommand($db);
$row = $command->queryOne(); $row = $command->queryOne();
if ($row !== false && !$this->asArray) { if ($row !== false) {
if ($this->asArray) {
$model = $row;
} else {
/** @var $class ActiveRecord */ /** @var $class ActiveRecord */
$class = $this->modelClass; $class = $this->modelClass;
$model = $class::create($row); $model = $class::create($row);
}
if (!empty($this->with)) { if (!empty($this->with)) {
$models = array($model); $models = array($model);
$this->populateRelations($models, $this->with); $this->populateRelations($models, $this->with);
...@@ -135,7 +139,7 @@ class ActiveQuery extends Query ...@@ -135,7 +139,7 @@ class ActiveQuery extends Query
} }
return $model; return $model;
} else { } else {
return $row === false ? null : $row; 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