Skip to content

Commit

Permalink
+ Query::searchOne for redefining
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 26, 2017
1 parent dfb1362 commit 5cb9c71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function createCommand($db = null)
// lazy loading
if (is_array($this->via)) {
// via relation
/* @var $viaQuery ActiveQuery */
/** @var $viaQuery ActiveQuery */
list($viaName, $viaQuery) = $this->via;
if ($viaQuery->multiple) {
$viaModels = $viaQuery->all();
Expand Down Expand Up @@ -245,9 +245,13 @@ public function addSelect($columns)
*/
public function one($db = null)
{
$row = parent::one($db);
if ($this->asArray) {
return parent::one($db);
}

$row = $this->searchOne($db);

return $this->asArray ? $row : reset($this->populate([$row]));
return reset($this->populate([$row]));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function createCommand($db = null)
}

public function one($db = null)
{
return $this->searchOne($db);
}

public function searchOne($db = null)
{
return $this->limit(1)->addOption('batch', false)->search();
}
Expand Down

0 comments on commit 5cb9c71

Please sign in to comment.