得到当前 model 各种 relation 的名字
@return array
434403
public function getRelationNames()
    {
        $names = [];
        foreach ($this->getFields() as $field) {
            /**
             * @var Field $field
             */
            $relationshipName = $field->getRelationshipName($names);
            if ($relationshipName) {
                $names[] = $relationshipName;
            }
        }
        return $names;
    }
96491
protected function getRawRelations()
    {
        if (is_null($this->relations)) {
            $this->relations = DB::select(
                'SELECT DISTINCT
                 u.referenced_column_name AS `localKey`
                ,u.column_name AS `foreignKey`
                ,r.table_name AS `foreignTable`
                ,CASE WHEN u.TABLE_NAME = r.referenced_table_name THEN 1 ELSE 0 END selfReferences
                FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS r
                INNER JOIN information_schema.key_column_usage AS u ON u.CONSTRAINT_NAME = r.CONSTRAINT_NAME
                                                                   AND u.table_schema = r.constraint_schema
                                                                   AND u.table_name = r.table_name
                WHERE u.referenced_table_name = ? AND u.constraint_schema = ?;',
                [$this->tableName, $this->databaseName]
            );
        }

        return $this->relations;
    }
1061725
protected function getQuickSearchAttributes()
    {
        // skip foreign keys, relations are search in other way
        $foreignKeys = array_map(function ($foreignKey) {
            array_shift($foreignKey);
            return array_keys($foreignKey);
        }, $this->getTableSchema()->foreignKeys);
        $allAttributes = !empty($foreignKeys) ? array_diff(
            $this->safeAttributes(),
            call_user_func_array('array_merge', $foreignKeys)
        ) : $this->safeAttributes();
        $safeAttributes = [];
        $relationAttributes = [];
        $relations = $this->relations();

        foreach ($allAttributes as $attribute) {
            if (($pos = strpos($attribute, '.')) === false && !in_array($attribute, $relations)) {
                $safeAttributes[] = $attribute;
                continue;
            }
            if ($pos === false) {
                $relationName = $attribute;
                $attribute = null;
            } else {
                $relationName = substr($attribute, 0, $pos);
                $attribute = substr($attribute, $pos + 1);
            }

            if (!isset($relationAttributes[$relationName])) {
                $relationAttributes[$relationName] = $this->getQuickSearchRelation($this->getRelation($relationName), $this->scenario);
            }
            if ($attribute === null) {
                /** @var \yii\db\ActiveRecord $relationModel */
                $relationModel = $relationAttributes[$relationName]['model'];
                /** @var LabelsBehavior $labelsBehavior */
                $labelsBehavior = $relationModel->getBehavior('labels');
                foreach ($labelsBehavior->attributes as $rcAttribute) {
                    $relationAttributes[$relationName]['attributes'][] = $rcAttribute;
                }
            } else {
                $relationAttributes[$relationName]['attributes'][] = $attribute;
            }
        }
        return [$safeAttributes, $relationAttributes];
    }
1048576
public function parentModel()
    {
        if ($this->value
            && ($relation = $this->guessRelation())
            && ($model = $this->getModel())
            && method_exists($model, $relation)) {
            return $model->$relation;
        }
    }
639427
protected function eagerLoadRelations()
    {
        $query = $this->model;

        if (is_array($this->eagerLoadRelations)) {
            $eagerLoads = [];

            foreach ($this->eagerLoadRelations as $relation => $rules) {
                // case for relations[]=relation_name
                // with relation that is numeric
                $relation = (is_integer($relation)) ? $rules : $relation;

                // case for relations[relation_name][attributes][]=attrib_name
                // with relation that is a relation name
                if (is_array($rules) && array_key_exists('attributes', $rules)) {
                    $eagerLoads[$relation] = function ($q) use ($rules) {
                        // If query is instance of HasOneOrMany,
                        // make sure to select the parent key name as foreign key.
                        if (
                            $q instanceof HasOneOrMany &&
                            !in_array($fk = $q->getParent()->getForeignKey(), $rules['attributes'])
                        ) {
                            array_push($rules['attributes'], $fk);
                        }

                        $q->select($rules['attributes']);
                    };
                } else {
                    array_push($eagerLoads, $relation);
                }
            }

            return $query->with($eagerLoads);
        }

        return $query->with($this->eagerLoadRelations);
    }
19754
public function getCascadeDeletesRelations()
    {
        $names = $this->getCascadeDeletesRelationNames();

        return array_combine($names, array_map(function ($name) {
            $relation = method_exists($this, $name) ? $this->$name() : null;

            return $relation instanceof Relation ? $relation : null;
        }, $names));
    }
284518
public function getHasOnes()
    {
        $modelNameSpace = $this->relation->getReferencedModel();
        $list = [];
        $relationships = $this->modelManager->getRelations($modelNameSpace);
        foreach ($relationships as $relation) {
            $refType = $relation->getType();
            if ($refType == 1) {
                $list[] = $relation->getReferencedModel();
            }
        }

        return $list;
    }
77442
public function resolvedRelationshipKeys(): array
    {
        $includeMap = $this->includeMap();

        $keys = [];
        foreach ($this->resolvedIncludeKeys() as $includeKey) {
            $relations = $includeMap[$includeKey]['relation'] ?? [];
            if (\count($relations) > 0) {
                array_push($keys, ...$relations);
            }
        }

        return array_unique($keys);
    }
525836
public function getUserRelationRules()
    {
        $rules = [];
        if ($this->relationType == static::$relationMutual) {
            $rules = [
                [[$this->mutualTypeAttribute], 'in', 'range' => array_keys(static::$mutualTypes)],
                [[$this->mutualTypeAttribute], 'default', 'value' => static::$mutualTypeNormal],
            ];
        }
        return array_merge($rules, $this->getRemarkRules(),
            $this->getFavoriteRules(),
            $this->getGroupsRules(),
        $this->getOtherGuidRules());
    }
1009783
function getRelations() {
		if (!isset($this->relations)) {
			$this->relations = new Table\Relations($this);
		}
		return $this->relations;
	}
1208635
public function relations()
    {
        $email = Yii::app()->getModule('email');
        if (!empty($email->modelMap[get_class($this)]['relations']))
            return $email->modelMap[get_class($this)]['relations'];
        return parent::relations();
    }
854580
private function relationData()
    {
        $onData = collect($this->data)->reject(function ($value, $key) {
            return !str_contains($key, 'on');
        });

        $foreignKeys = collect($this->data)->reject(function ($value, $key) {
            return !str_contains($key, 'tbl');
        });

        $this->onData = array_values($onData->toArray());

        $this->foreignKeys = array_values($foreignKeys->toArray());
    }
118923
protected function getRelationData(Relation $modelRelation)
    {
        if ($this->parent && !$modelRelation->isSelfRelation() && get_class($this->parent) == get_class($modelRelation->getModel())) {
            $value = $this->parent;
        } else {
            // 获取关联数据
            $value = $modelRelation->getRelation();
        }

        return $value;
    }
1021710
public function getRelationTable()
    {
        if (is_null($this->_relationTable)) {
            $names = [
                $this->getEntity()->getTableName(),
                Entity\Manager::getInstance()
                    ->get($this->_relatedEntity)
                    ->getEntity()->getTableName()
            ];
            asort($names);
            $this->setRelationTable(implode('_', $names));
        }
        return $this->_relationTable;
    }
1312940
public function getDirtyRelations()
    {
        $dirtyRelations = [];
        foreach ($this->_relations as $relationName) {
            if (array_key_exists($relationName, $this->_oldRelationValue)) {
                $dirtyRelations[$relationName] = $this->owner->{$relationName};
            }
        }
        return $dirtyRelations;
    }
94032
public function getRelationDictionary(string $relationName): array
    {
        return $this->models
            ->mapWithKeys(
                function (Model $model) use ($relationName) {
                    return [$this->buildKey($model->getKey()) => $model->getRelation($relationName)];
                }
            )->all();
    }
597315
protected function determineRelations()
    {
        if (count($this->parameters)) {
            return $this->parameters;
        }

        if ( ! ($info = $this->getModelInformation())) {
            return [];
        }

        return array_pluck($info->relations, 'method');
    }