query prepareResult return one column

This commit is contained in:
evgen-d 2014-10-23 15:03:48 +04:00
parent 1f23259b58
commit acaf1780bc

View File

@ -796,19 +796,23 @@ class Query extends Component implements QueryInterface
public function prepareResult($rows) public function prepareResult($rows)
{ {
$result = []; $result = [];
if ($this->indexBy === null) { if (isset($rows[0]) && $rows[0] instanceof Document) {
foreach ($rows as $row) { if ($this->indexBy === null) {
$result[] = $row->getAll(); foreach ($rows as $row) {
$result[] = $row->getAll();
}
} else {
foreach ($rows as $row) {
if (is_string($this->indexBy)) {
$key = $row->{$this->indexBy};
} else {
$key = call_user_func($this->indexBy, $row);
}
$result[$key] = $row->getAll();
}
} }
} else { } else {
foreach ($rows as $row) { $result = $rows;
if (is_string($this->indexBy)) {
$key = $row->{$this->indexBy};
} else {
$key = call_user_func($this->indexBy, $row);
}
$result[$key] = $row->getAll();
}
} }
return $result; return $result;
} }