Skip to content

Commit

Permalink
Refactored ActiveQuery::one() to be consistent with all() creation
Browse files Browse the repository at this point in the history
  • Loading branch information
slavcodev committed Jul 31, 2014
1 parent 09fc0c3 commit fa8e576
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions framework/db/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,8 @@ public function one($db = null)
{
$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;
}
Expand Down

0 comments on commit fa8e576

Please sign in to comment.