made indexBy callable like db AR

This commit is contained in:
Carsten Brandt
2013-09-24 19:09:59 +02:00
parent 3623fc19dc
commit 7850c8d238
2 changed files with 22 additions and 2 deletions

View File

@@ -642,7 +642,12 @@ class ActiveQuery extends \yii\base\Component
return $rows;
}
foreach ($rows as $row) {
$models[$row[$this->indexBy]] = $row;
if (is_string($this->indexBy)) {
$key = $row[$this->indexBy];
} else {
$key = call_user_func($this->indexBy, $row);
}
$models[$key] = $row;
}
} else {
/** @var $class ActiveRecord */
@@ -654,7 +659,12 @@ class ActiveQuery extends \yii\base\Component
} else {
foreach ($rows as $row) {
$model = $class::create($row);
$models[$model->{$this->indexBy}] = $model;
if (is_string($this->indexBy)) {
$key = $model->{$this->indexBy};
} else {
$key = call_user_func($this->indexBy, $model);
}
$models[$key] = $model;
}
}
}