Match the results for a given type to their parents.

@param  string  $type
@param  array  $results
@return void
502955
protected function matchToMorphParents($type, array $results)
    {
        foreach ($results as $result) {
            if (isset($this->dictionary[$type][$result->getKey()])) {
                foreach ($this->dictionary[$type][$result->getKey()] as $model) {
                    $model->setRelation($this->relation, $result);
                }
            }
        }
    }
122261
private function resolveAndAddType(ObjectTypeInterface $type): void
    {
        $parentType = $type->getParent();
        $typeExtensions = [];

        foreach ($this->extensions as $extension) {
            /** @var ObjectExtensionInterface $extension */
            $typeExtensions = array_merge(
                $typeExtensions,
                $extension->getTypeExtensions('default'),
                $extension->getTypeExtensions($type->getClass())
            );
        }

        $parent = $parentType ? $this->getType($parentType) : null;
        $rType = $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parent);

        $this->types[$type->getClass()] = $rType;
    }
368064
protected function processResult(array $results)
    {
        foreach ($results as $key => $entity) {

            if (!empty($entity['data'])) {

                $entity['data'] = $this->decorator->denormalizeValue($entity['data']);
                $results[$key] = $entity;
            }
        }

        return $results;
    }
755016
protected function success($results = null)
    {
        $this->trigger('json-success', $this, $results);
        $this->trigger('response-success', $this, $results);

        $json = array('error' => false);

        if($results) {
            $json['results'] = $results;
        }

        $body = json_encode($json, JSON_PRETTY_PRINT);

        $this->response
            ->set('headers', 'Content-Type', 'text/json')
            ->set('body', $body);

        return $body;
    }
138986
public void setResults(java.util.Collection<SearchRecord> results) {
        if (results == null) {
            this.results = null;
            return;
        }

        this.results = new java.util.ArrayList<SearchRecord>(results);
    }
569193
private function castResult($result)
    {
        try {
            $result = $this->typeAdapter->toArray($result);
        } catch (TypeCastException $exception) {
            return $result;
        }

        return $result;
    }
711064
public function match(array $models, Collection $results, $relation)
    {
        // This relationship deals with a One-To-One morph type so we'll just extract
        // the first model out of the results and return it.
        $matched = parent::match($models, $results, $relation);

        return array_map(function($match) use ($relation)
        {
            if (isset($match[$relation]) && isset($match[$relation][0]))
            {
                $match->setRelation($relation, $match[$relation][0]);
            }

            return $match;

        }, $matched);
    }
1335149
public function buildRelation(array $models, array $results) {
        foreach ($models as &$model) {
            if ($model instanceof Model) {
                $model->setRelation($this->getKey(), $this->matchRelation($model, $results));
                continue;
            }
            $model[$this->getKey()] = $this->matchRelation($model, $results);
        }
        unset($model);
        return $models;
    }
171534
public function castResults(Event $event, array &$results, $finder) {
        $columns = $this->getSchema()->getColumns();
        $driver = $this->getDriver();
        $entityClass = $this->getEntity();

        foreach ($results as $i => $result) {
            foreach ($result as $field => $value) {
                if (isset($columns[$field])) {
                    $result[$field] = $driver->getType($columns[$field]['type'])->from($value);
                }

                if (!is_array($value)) {
                    continue;
                }

                $result[$field] = new Entity($value);
            }

            $results[$i] = new $entityClass($result);
        }
    }
672620
public function match(array $models, Collection $results, $relation)
    {
        return $this->matchOneOrMany($models, $results, $relation, 'many');
    }
900343
public function setResults($results = null, bool $stopPropagation = false) {
        $this->result = $results;
        if ($stopPropagation) {
            $this->stopPropagation();
        }
    }
968384
protected function setFieldResults(array $fieldResults)
    {
        foreach ($fieldResults as $fieldName => $validationResult) {
            $this->setFieldResult($fieldName, $validationResult);
        }
    }
1251878
private function isSent($results)
    {
        return array_key_exists(self::MESSAGE_ID, $results) && !array_key_exists(self::REGISTRATION_ID, $results);
    }
1200013
protected function mergeCacheResults(array $results)
    {
        foreach ($results as $key => $entity) {
            $this->cache[$key] = $entity;
        }
    }
184656
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);
    }
1320113
public function processColumnListing($results)
    {
        return array_values(array_map(function ($result)
        {
            $result = (object) $result;

            return $result->column_name;

        }, $results));
    }
584409
public function match(array $results, $relation)
    {
        $foreign = $this->foreignKey;

        $other = $this->otherKey;

        // Execute the relationship and get related entities as an EntityCollection
        $entities = $this->getEager();

        // First we will get to build a dictionary of the child models by their primary
        // key of the relationship, then we can easily match the children back onto
        // the parents using that dictionary and the primary key of the children.
        $dictionary = [];

        // TODO ; see if otherKey is the primary key of the related entity, we can
        // simply use the EntityCollection key to match entities to results, which
        // will be much more efficient, and use this method as a fallback if the
        // otherKey is not the same as the primary Key.
        foreach ($entities as $entity) {
            $entity = $this->factory->make($entity);
            $dictionary[$entity->getEntityAttribute($other)] = $entity->getObject();
        }

        // Once we have the dictionary constructed, we can loop through all the parents
        // and match back onto their children using these keys of the dictionary and
        // the primary key of the children to map them onto the correct instances.
        return array_map(function ($result) use ($dictionary, $foreign, $relation) {
            if (array_key_exists($foreign, $result) && isset($dictionary[$result[$foreign]])) {
                $result[$relation] = $dictionary[$result[$foreign]];
            } else {
                $result[$relation] = null;
            }

            return $result;
        }, $results);
    }