Get the foreign ID and type for creating a related model.

@return array
435035
protected function getForeignAttributesForCreate()
	{
		$foreign = array($this->getPlainForeignKey() => $this->getParentKey());

		$foreign[last(explode('.', $this->morphType))] = $this->morphClass;

		return $foreign;
	}
1134501
public function getForeignKey()
    {
        if (is_null($this->foreignKey)) {
            $name = $this->getParentEntityDescriptor()->getTableName();
            $this->foreignKey = "{$this->normalizeFieldName($name)}_id";
        }
        return $this->foreignKey;
    }
1019043
protected function getMemberIDList()
    {
        if (!$this->owner || !$this->owner->exists()) {
            return null;
        }

        if ($this->owner instanceof Group) {
            return $this->owner->Members()->column('ID');
        }

        return [$this->owner->ID];
    }
1126817
public function getRelation()
    {
        if (!$this->relatedTableName) {
            return null;
        }
        foreach ($this->getTable()->getRelations() as $name => $relation) {
            if ($relation->getType() == RelationMap::MANY_TO_ONE) {
                if ($relation->getForeignTable()->getName() == $this->getRelatedTableName() && array_key_exists($this->getFullyQualifiedName(), $relation->getColumnMappings())) {
                    return $relation;
                }
            }
        }
    }
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];
    }
297597
protected function getRelations()
    {
        $relations = [];
        $rawRelations = $this->getRawRelations();
        foreach ($rawRelations as $rawRelation) {
            $relations[] = $this->getRealtion($rawRelation->foreignTable, $rawRelation->foreignKey, $rawRelation->localKey, $rawRelation->selfReferences);
        }

        return $relations;
    }
978108
public function type() {
		if($this->get('relation_type'))
			return $this->get('relation_type');
		elseif($this->get('poymorphic'))
			throw new \Exception('Parameter relation_type must be provided for polymorphic relations.');

		$rev = $this->reverse();

		if($this->get('many')) {
			if($rev->get('many'))
				return 'HMABT';
			else
				return 'hasMany';
		}
		else {
			if($rev->get('many'))
				return 'belongsTo';
			else
				return 'hasOne';
		}
	}
140287
public function getAttributes()
    {
        return [
            Attributes\IdAttribute::make(),
            Attributes\TextAttribute::make('name')
                ->setRequired(true),
            Attributes\TextAttribute::make('code'),
            Attributes\BelongsToAttribute::make('legal_entity_id')
                ->setRelationName('legal_entity')
                ->setRelationManager(LegalEntityManager::class),
            Attributes\CreatedAtAttribute::make(),
            Attributes\UpdatedAtAttribute::make(),
            Attributes\DeletedAtAttribute::make(),
        ];
    }
352373
public function getRelatedColumns()
	{
		//make sure we only run this once and then return the cached version
		if (!sizeof($this->relatedColumns))
		{
			foreach ($this->getColumns() as $column)
			{
				if ($column->getOption('is_related'))
				{
					$this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name');
				}
			}
		}

		return $this->relatedColumns;
	}
1225536
public function getTypes()
    {
        $types = $this->config()->get('types');

        if ($this->allowed_types) {
            // Prioritise local field over global settings
            $allowed_types = $this->allowed_types;
        }
        if ($allowed_types = $this->config()->get('allowed_types')) {
           foreach ($allowed_types as $type) {
                if (!array_key_exists($type, $types)) {
                    user_error("{$type} is not a valid link type");
                }
            }

            foreach (array_diff_key($types, array_flip($allowed_types)) as $key => $value) {
                unset($types[$key]);
            }
        }
        $this->extend('updateTypes', $types);
        return $types;
    }
347259
private function getRelatedModel()
    {
        $idSuffix = '_id';

        return substr($this->key, 0, strlen($this->key) - strlen($idSuffix));
    }
1303758
public function getContent()
    {
        return strtr($this->getRelationStubContent(), [
            '{{name}}'         => $this->name,
            '{{relatedTable}}' => $this->relatedModel->getTable(),
            '{{relatedModel}}' => $this->relatedModel->getClass(),
            '{{foreignKey}}'   => $this->foreignKey,
        ]);
    }
62376
protected function getForeignKeyAttributesFromParent(): array
    {
        $parentMap = $this->parent->getEntityMap();

        $parentForeignRelations = $parentMap->getForeignRelationships();
        $parentPivotRelations = $parentMap->getPivotRelationships();

        // The parentRelation is the name of the relationship
        // methods on the parent entity map
        $parentRelation = $this->parentRelationship;

        if (in_array($parentRelation, $parentForeignRelations) &&
            !in_array($parentRelation, $parentPivotRelations)
        ) {
            $parentObject = $this->parent->getEntityObject();

            // Call Relationship's method on parent map
            $relationship = $parentMap->$parentRelation($parentObject);

            return $relationship->getForeignKeyValuePair($parentObject);
        }

        return [];
    }
326319
public function getQueueableId()
    {
        if (isset($this->attributes[$this->getKeyName()])) {
            return $this->getKey();
        }

        return sprintf(
            '%s:%s:%s:%s:%s:%s',
            $this->foreignKey, $this->getAttribute($this->foreignKey),
            $this->relatedKey, $this->getAttribute($this->relatedKey),
            $this->morphType, $this->morphClass
        );
    }
698730
public function getForeignKey()
    {
        if (is_null($this->_foreignKey)) {
            $this->setForeignKey($this->_guessForeignKey());
        }
        return $this->_foreignKey;
    }
505747
public function getForeignKey()
    {
        if (is_null($this->foreignKey)) {
            $name = $this->getEntityDescriptor()->getTableName();
            $this->foreignKey = "{$this->normalizeFieldName($name)}_id";
        }
        return $this->foreignKey;
    }
4445
public function getForeignKey()
    {
        if ($this->_foreignKey === null) {
            $this->_foreignKey = $this->_modelKey($this->getSource()->getTable());
        }

        return $this->_foreignKey;
    }