lithium\data\model\Relationship::_index()
Indexes a collection.
Parameters
-
mixed
$collection An collection to extract index from.
-
string
$name
The field name to build index for.
Returns
arrayAn array of indexes where keys are $name
values and
values the correcponding index in the collection.
Source
protected function _index($collection, $name) {
$indexes = [];
foreach ($collection as $key => $entity) {
$id = is_object($entity) ? $entity->{$name} : $entity[$name];
$indexes[(string) $id] = $key;
}
return $indexes;
}