LMongo\Eloquent\Relations\HasOneOrMany::buildDictionary PHP Method

buildDictionary() protected method

Build model dictionary keyed by the relation's foreign key.
protected buildDictionary ( Collection $results ) : array
$results LMongo\Eloquent\Collection
return array
    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) {
            $dictionary[(string) $result->{$this->foreignKey}][] = $result;
        }
        return $dictionary;
    }