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

matchOneOrMany() protected method

Match the eagerly loaded results to their many parents.
protected matchOneOrMany ( array $models, Collection $results, string $relation, string $type ) : array
$models array
$results LMongo\Eloquent\Collection
$relation string
$type string
return array
    protected function matchOneOrMany(array $models, Collection $results, $relation, $type)
    {
        $dictionary = $this->buildDictionary($results);
        // Once we have the dictionary we can simply spin through the parent models to
        // link them up with their children using the keyed dictionary to make the
        // matching very convenient and easy work. Then we'll just return them.
        foreach ($models as $model) {
            $key = $model->getKey();
            if (isset($dictionary[$key])) {
                $value = $this->getRelationValue($dictionary, $key, $type);
                $model->setRelation($relation, $value);
            }
        }
        return $models;
    }