From d1ebf655974093388b4e01551aa8303b7e82414a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 15:07:23 -0400 Subject: [PATCH] Fixed the issue that ActiveQuery::one() doesn't bring back related objects when asArray is true. --- framework/yii/db/ActiveQuery.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/framework/yii/db/ActiveQuery.php b/framework/yii/db/ActiveQuery.php index e0c40f7..4d08659 100644 --- a/framework/yii/db/ActiveQuery.php +++ b/framework/yii/db/ActiveQuery.php @@ -124,10 +124,14 @@ class ActiveQuery extends Query { $command = $this->createCommand($db); $row = $command->queryOne(); - if ($row !== false && !$this->asArray) { - /** @var $class ActiveRecord */ - $class = $this->modelClass; - $model = $class::create($row); + if ($row !== false) { + if ($this->asArray) { + $model = $row; + } else { + /** @var $class ActiveRecord */ + $class = $this->modelClass; + $model = $class::create($row); + } if (!empty($this->with)) { $models = array($model); $this->populateRelations($models, $this->with); @@ -135,7 +139,7 @@ class ActiveQuery extends Query } return $model; } else { - return $row === false ? null : $row; + return null; } }