获取查询结果
@param array $models
@return array|mixed|object[]
@throws \Exception
779156
public function getResults($models) {
        $is_one = !is_array($models) || !is_array(reset($models));
        if ($is_one) {
            $models = [$models];
        }
        $results = $this->getQueryResults($models);
        if (empty($results) || !$is_one) {
            return $results;
        }
        return $this->type == self::TYPE_ONE ? reset($results) : $results;
    }
518707
protected static function isSomeArr($models) {
        if (!is_array($models)) {
            return false;
        }
        $model = reset($models);
        return is_array($model) || $model instanceof Model;
    }
576556
public function addEagerConstraints(array $models)
    {
        $keys = $this->getKeys($models, $this->getFirstForeignKeyName());

        $this->query->whereIn($this->getQualifiedFirstLocalKeyName(), $keys);
    }
302887
public function setModels(array $models): ModelCollectionInterface
    {
        foreach ($this->models as $model) {
            $this->removeModel($model);
        }
        foreach ($models as $model) {
            $this->addModel($model);
        }

        return $this;
    }
864003
protected function getIncludedModels($models)
    {
        $links = new Collection();
        $models = $models instanceof Collection ? $models : [$models];

        foreach ($models as $model) {
            foreach ($this->exposedRelationsFromRequest($model) as $relationName) {
                $value = static::getModelsForRelation($model, $relationName);

                if (is_null($value)) {
                    continue;
                }

                foreach ($value as $obj) {

                    // Check whether the object is already included in the response on it's ID
                    $duplicate = false;
                    $items = $links->where($obj->getKeyName(), '=', $obj->getKey());
                    if (count($items) > 0) {
                        foreach ($items as $item) {
                            if ($item->getResourceType() === $obj->getResourceType()) {
                                $duplicate = true;
                                break;
                            }
                        }
                        if ($duplicate) {
                            continue;
                        }
                    }

                    //add type property
                    $attributes = $obj->getAttributes();
                    $attributes['type'] = $obj->getResourceType();
                    $obj->setRawAttributes($attributes);

                    $links->push($obj);
                }
            }
        }

        return $links->toArray();
    }
1006073
public function getModels ($entities)
    {
        $models = array();

        foreach ($entities as $entity) {
            $models[] = $this->getModel($entity);
        }

        return $models;
    }
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;
    }
1076121
protected function getKeys(array $models, $key = null)
    {
        return array_unique(array_values(array_map(function($value) use ($key)
        {
            if (is_array($value)) $value = reset($value);

            return $key ? $value->getAttribute($key) : $value->getKey();

        }, $models)));
    }
595414
protected static function buildMorphMapFromModels(array $models = null)
    {
        if (is_null($models) || Arr::isAssoc($models)) {
            return $models;
        }

        return array_combine(array_map(function ($model) {
            return (new $model)->getTable();
        }, $models), $models);
    }
566768
public static function create($models, array $relations) {
        $is_one = !static::isSomeArr($models);
        if ($is_one) {
            $models = [$models];
        }
        foreach ($relations as $key => $relation) {
            $relation = static::parse($relation, $key);
            $models =  $relation->getWithMulti($models);
        }
        return $is_one ? reset($models) : $models;
    }
1270620
public function getModels($columns = ['*'])
    {
        $models = [];

        $documents = $this->query->get($columns);
        foreach ($documents as $doc) {
            $models[] = $this->model->newInstance($doc, true);
        }

        return $models;
    }
957595
public static function compositeIDs($models)
    {
        if (!is_array($models) && $models instanceof static) {
            return $models->getID();
        }
        $ids = [];
        foreach ($models as $model) {
            if ($model instanceof static) {
                $ids[] = $model->getID();
            }
        }
        return $ids;
    }
21519
public function handleModels(array $models)
    {
        $builder = $this->builder;

        $builder->start();

        foreach ($models as $model) {
            $languages = (array)(isset($model->sitemapLanguages) ? $model->sitemapLanguages : Yii::$app->language);

            if (count($languages) > 1) {
                // Handle separately for each language
                foreach ($languages as $language) {
                    // Swith App language to $language
                    if (isset($model->sitemapSwithLanguages) && $model->sitemapSwithLanguages) {
                        static::setLanguage($language);
                    }

                    $this->handleModel($model, $language);

                    // Restore App language
                    static::restoreLanguage();
                }
            } else {
                // Handle only one language
                $this->handleModel($model, null);
            }
        }

        $builder->finish();
    }
911515
public function set($models)
    {
        if ($models instanceof ActiveRecord) {
            $models = [$models];
        }

        $first = reset($models);
        if ($first === false) {
            return $this;
        }
        $this->first = $first;

        $this->formName = $first->formName();
        $this->model    = $this->setModel($first);
        $this->models   = $models;

        if ($this->checkConsistency && !$this->isConsistent()) {
            throw new InvalidValueException('Models are not objects of same class or not follow same operation');
        }

        return $this;
    }
844787
public function get($columns = ['*'])
    {
        $models = parent::get($columns);

        $this->hydrateIntermediateRelations($models->all());

        return $models;
    }
659192
public static function getInCondition(&$models)
    {

        $inArray = array_filter(
            ArrayHelper::getColumn($models, 'id', false),
            function ($val) {
                return $val !== null;
            }
        );
        return $inArray === [] ? [] : ['model_id' => $inArray];
    }
631598
public function batchLoadFor($models, $subWiths) {
        $ids = [];
        foreach ($models as $model) {
            $id = $model->properties[$this->prop];
            if (is_string($id)) {
                $ids[] = "'$id'";
            } elseif (is_int($id)) {
                $ids[] = $id;
            } elseif ($id !== null) {
                X::logger()->warn('Unsupported reference type ' . gettype($id)
                    . ' of ' . get_class($model) . '->' . $this->prop
                    . ' (PK: ' . $model->pk . ')'
                );
            }
        }
        if (count($ids) === 0) {
            return;
        }
        $idStr = implode(',', $ids);
        /** @var Model[] $foreignModels */
        $foreignModels = $this->model
            ->with(...$subWiths)
            ->many("`{$this->model->pkName}` IN ($idStr)");
        $map = [];
        foreach ($foreignModels as $foreignModel) {
            $map[$foreignModel->pk] = $foreignModel;
        }
        foreach ($models as $model) {
            $model->{$this->name} = $map[$model->properties[$this->prop]] ?? null;
        }
    }