Map the given results to instances of the given model.
@param  mixed  $results
@param  \Illuminate\Database\Eloquent\Model  $model
@return Collection
978494
public function map($results, $model)
    {
        if ($results['hits']['total'] === 0) {
            return Collection::make();
        }

        $keys = collect($results['hits']['hits'])
            ->pluck('_id')->values()->all();

        $models = $model->whereIn(
            $model->getKeyName(), $keys
        )->get()->keyBy($model->getKeyName());

        return collect($results['hits']['hits'])->map(function ($hit) use ($model, $models) {
            return $models[$hit['_id']];
        });
    }
1289191
protected function buildDictionary(Collection $results)
    {
        $dictionary = [];

        // 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[$result->laravel_through_key][] = $result;
        }

        return $dictionary;
    }
454305
public function createIteration(array $results = [])
    {
        $index = count($this->iterations);
        $iteration = new Iteration($index, $this, $results);
        $this->iterations[] = $iteration;

        return $iteration;
    }
786494
protected function from_db_records(array $results) {
        $entityfactory = $this->get_entity_factory();
        $records = array_map(function($result) {
            return $result['record'];
        }, $results);

        return $entityfactory->get_post_read_receipt_collection_from_stdclasses($records);
    }
804743
public function match(array $models, Collection $results, $relation)
    {
        $foreign = $this->foreignKey;

        $other = $this->otherKey;

        $dictionary = array();

        foreach ($results as $result) {
            $dictionary[$result->getAttribute($other)] = $result;
        }

        foreach ($models as $model) {
            if (isset($dictionary[$model->$foreign])) {
                $model->setRelation($relation, $dictionary[$model->$foreign]);
            }
        }

        return $models;
    }
1364738
public function eagerLoadRelations(array $results): array
    {
        foreach ($this->eagerLoads as $name => $constraints) {
            // First, we'll check if the entity map has a relation and just pass if it
            // is not the case

            if (!in_array($name, $this->entityMap->getRelationships())) {
                continue;
            }

            // For nested eager loads we'll skip loading them here and they will be set as an
            // eager load on the query to retrieve the relation so that they will be eager
            // loaded on that query, because that is where they get hydrated as models.
            if (strpos($name, '.') === false) {
                $results = $this->loadRelation($results, $name, $constraints);
            }
        }

        return $results;
    }
219297
protected function transformResultsToRoutes(array $results)
    {
        $routes = [];
        foreach ($results as $result) {
            $name = $result['route'];
            if (array_key_exists($name, $routes)) {
                /** @var Route $route */
                $route = $routes[$name];
                $paths = $route->getOption('i18n_paths');
                $paths[$result['locale']] = $result['path'];
                $route->setOption('i18n_paths', $paths);
            } else {
                $route = new Route($result['path']);
                if (!array_key_exists($result['controller'], $this->config['controllers'])) {
                    throw new \RuntimeException(sprintf('Undefined controller "%s".', $result['controller']));
                }
                $paths = [$result['locale'] => $result['path']];
                $route
                    ->setDefault('_controller', $this->config['controllers'][$result['controller']]['value'])
                    ->setMethods(['GET'])
                    ->setOption('i18n_paths', $paths)
                ;
                $routes[$name] = $route;
            }
        }
        // TODO check that i18n_paths are set for all locales ?
        return $routes;
    }
717414
private function processResults($results)
    {
        $entries = $this->connection->getEntries($results);

        $objects = [];

        if (array_key_exists('count', $entries)) {
            for ($i = 0; $i < $entries['count']; $i++) {
                $entry = $this->newLdapEntry($entries[$i], $this->connection);

                $objects[] = $entry->getAttributes();
            }

            if (!empty($this->sortByField)) {
                return $this->processSortBy($objects);
            }
        }

        return $objects;
    }
370088
public function build($result)
    {
        $modelResult = new ModelResult($this);
        $modelResult->models = $result;
        if (count($result) > 0) {
            $modelResult->model = $result[0];
        }
        if ($this->order !== '') {
            $modelResult->order($this->order);
        }
        return $modelResult;
    }
726603
public function match(array $models, Collection $results, $relation)
    {
        return $this->matchMany($models, $results, $relation);
    }
825881
public function find_many()
        {
            $results = parent::find_many();

            foreach($results as $key => $result) {
                $results[$key] = $this->_createModelInstance($result);
            }

            return $results;
        }
787700
public function processColumnListing($results)
    {
        $mapping = function ($r) {
            $r = (object) $r;

            return $r->column_name;
        };

        return array_map($mapping, $results);
    }
751893
public static function parseRelationShips(string $relationships, &$results) : array
    {
        $relationships = explode(',', $relationships);

        $newResults = [];

        if (!($results instanceof Model)) {
            throw new Exception(_('Result needs to be a Baka Model'));
        }

        $newResults = $results->toFullArray();
        foreach ($relationships as $relationship) {
            if ($results->$relationship) {
                $newResults[$relationship] = $results->$relationship;
            }
        }

        unset($results);
        return $newResults;
    }
386124
public function afterFind(Model $model, $results, $primary = true) {
        $alias = $model->alias;

        if (!$this->format || ($model->id && !$this->onUpdate) || empty($this->_enums[$alias])) {
            return $results;
        }

        if ($results) {
            $enum = $this->_enums[$alias];

            foreach ($results as &$result) {
                foreach ($enum as $key => $nop) {
                    if (isset($result[$alias][$key])) {
                        $value = $result[$alias][$key];

                        if ($this->format === self::REPLACE) {
                            $result[$alias][$key] = $this->enum($model, $key, $value);

                            if ($this->persist) {
                                $result[$alias][$key . $this->suffix] = $value;
                            }
                        } else if ($this->format === self::APPEND) {
                            $result[$alias][$key . $this->suffix] = $this->enum($model, $key, $value);
                        }
                    }
                }
            }
        }

        return $results;
    }
514361
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            $translations = (array)$row['_i18n'];
            if (count($translations) === 0 && $row->get('_translations')) {
                return $row;
            }

            $result = [];
            foreach ($translations as $translation) {
                unset($translation['id']);
                $result[$translation['locale']] = $translation;
            }

            $row['_translations'] = $result;
            unset($row['_i18n']);
            if ($row instanceof EntityInterface) {
                $row->clean();
            }

            return $row;
        });
    }
433319
public function mapModels($rows){
        $rst = array();
        foreach($rows as $row){
            $rst[] = $this->map($row);
        }
        
        return $rst;
    }
1270259
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            if (!$row instanceof EntityInterface) {
                return $row;
            }
            $translations = (array)$row->get('_i18n');
            if (empty($translations) && $row->get('_translations')) {
                return $row;
            }
            $grouped = new Collection($translations);

            $result = [];
            foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
                $entityClass = $this->_table->getEntityClass();
                $translation = new $entityClass($keys + ['locale' => $locale], [
                    'markNew' => false,
                    'useSetters' => false,
                    'markClean' => true
                ]);
                $result[$locale] = $translation;
            }

            $options = ['setter' => false, 'guard' => false];
            $row->set('_translations', $result, $options);
            unset($row['_i18n']);
            $row->clean();

            return $row;
        });
    }