protected function buildDictionary(Collection $results)
{
$dictionary = array();
// First we will create a dictionary of models keyed by the foreign key of the
// relationship as this will allow us to quickly access all of the related
// models without having to do nested looping which will be quite slow.
foreach ($results as $result) {
foreach ($result->{$this->foreignKey} as $key) {
$dictionary[(string) $key][] = $result;
}
}
return $dictionary;
}