public function match(array $results, $relation)
    {
        $entities = $this->getEager();

        // TODO; optimize this operation
        $dictionary = $this->buildDictionary($entities);

        $keyName = $this->parentMap->getKeyName();

        $cache = $this->parentMapper->getEntityCache();

        $host = $this;

        // Once we have an array dictionary of child objects we can easily match the
        // children back to their parent using the dictionary and the keys on the
        // the parent models. Then we will return the hydrated models back out.
        return array_map(function ($result) use ($dictionary, $keyName, $cache, $relation, $host) {
            $key = $result[$keyName];

            if (isset($dictionary[$key])) {
                $collection = $host->relatedMap->newCollection($dictionary[$key]);

                $result[$relation] = $collection;

                // TODO Refactor this
                $cache->cacheLoadedRelationResult($key, $relation, $collection, $this);
            } else {
                $result[$relation] = $host->relatedMap->newCollection();
            }

            return $result;
        }, $results);
    }
public function match(array $results, $relation)
    {
        $entities = $this->getEager();

        // TODO; optimize this operation
        $dictionary = $this->buildDictionary($entities);

        $keyName = $this->parentMap->getKeyName();

        $cache = $this->parentMapper->getEntityCache();

        $host = $this;

        // Once we have an array dictionary of child objects we can easily match the
        // children back to their parent using the dictionary and the keys on the
        // the parent models. Then we will return the hydrated models back out.
        return array_map(function ($result) use ($dictionary, $keyName, $cache, $relation, $host) {
            $key = $result[$keyName];

            if (isset($dictionary[$key])) {
                $collection = $host->relatedMap->newCollection($dictionary[$key]);

                $result[$relation] = $collection;

                // TODO Refactor this
                $cache->cacheLoadedRelationResult($key, $relation, $collection, $this);
            } else {
                $result[$relation] = $host->relatedMap->newCollection();
            }

            return $result;
        }, $results);
    }
public function match ( array $ results , $ relation ) { $ entities = $ this -> getEager ( ) ; // TODO; optimize this operation $ dictionary = $ this -> buildDictionary ( $ entities ) ; $ keyName = $ this -> parentMap -> getKeyName ( ) ; $ cache = $ this -> parentMapper -> getEntityCache ( ) ; $ host = $ this ; // Once we have an array dictionary of child objects we can easily match the // children back to their parent using the dictionary and the keys on the // the parent models. Then we will return the hydrated models back out. return array_map ( function ( $ result ) use ( $ dictionary , $ keyName , $ cache , $ relation , $ host ) { $ key = $ result [ $ keyName ] ; if ( isset ( $ dictionary [ $ key ] ) ) { $ collection = $ host -> relatedMap -> newCollection ( $ dictionary [ $ key ] ) ; $ result [ $ relation ] = $ collection ; // TODO Refactor this $ cache -> cacheLoadedRelationResult ( $ key , $ relation , $ collection , $ this ) ; } else { $ result [ $ relation ] = $ host -> relatedMap -> newCollection ( ) ; } return $ result ; } , $ results ) ; }
Match Eagerly loaded relation to result.

@param array  $results
@param string $relation

@return array
Match Eagerly loaded relation to result .