@param ForeignKey $foreignKey

@throws InvalidArgumentException

@return Column
499421
final public function addForeignKey(ForeignKey $foreignKey): Column
    {
        if (array_key_exists($foreignKey->getName(), $this->foreignKeys)) {
            throw new InvalidArgumentException('Foreign key '.$foreignKey->getName().' already added.');
        }

        $this->foreignKeys[$foreignKey->getName()] = $foreignKey;

        return $this;
    }
312848
protected function getForeignKeySQLDeclaration(ForeignKey $foreignKey)
    {
        if (!$this->supportForeignKeys()) {
            throw PlatformException::methodNotSupported(__METHOD__);
        }

        return 'CONSTRAINT '.$foreignKey->getName().
               ' FOREIGN KEY'.
               ' ('.implode(', ', $foreignKey->getLocalColumnNames()).')'.
               ' REFERENCES '.$foreignKey->getForeignTableName().
               ' ('.implode(', ', $foreignKey->getForeignColumnNames()).')'.
               ' ON DELETE '.$foreignKey->getOnDelete().
               ' ON UPDATE '.$foreignKey->getOnUpdate();
    }
954969
public function hasOne($related, $foreignKey = null, $localKey = null)
    {
        if (is_array($foreignKey)) { //Check for multi-columns relationship
            $this->validateRelatedModel($related);
        }

        $instance = $this->newRelatedInstance($related);

        $foreignKey = $foreignKey ?: $this->getForeignKey();

        $foreignKeys = null;

        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $key) {
                $foreignKeys[] = $this->sanitizeKey($instance, $key);
            }
        } else {
            $foreignKey = $this->sanitizeKey($instance, $foreignKey);
        }

        $localKey = $localKey ?: $this->getKeyName();

        return new HasOne($instance->newQuery(), $this, $foreignKeys ?: $foreignKey, $localKey);
    }
412390
protected function fetchOneToMany($foreign_class, $foreign_column, $column)
    {
        return $foreign_class::select($this->connection)
            ->where($foreign_column, '=', $this->getRaw($column))
            ->execute();
    }
1374280
public function on($foreignKey, $key = null) {
        if (is_array($foreignKey)) {
            $this->_conditions = array_replace($this->_conditions, $foreignKey);
        } else {
            $this->_conditions[$foreignKey] = $key;
        }

        return $this;
    }
1142529
public function belongsTo($name, $foreignKey, $modelName = null)
    {
        $this->addAssociation('belongsTo', $name, $foreignKey, $modelName);
        return $this;
    }
533438
public function on(string $referencedTableName) : ForeignKeyOnDeleteModeDefiner
    {
        return new ForeignKeyOnDeleteModeDefiner(
                $this->callback,
                $this->localColumnNames,
                $this->referencedColumnNames,
                $referencedTableName
        );
    }
1026437
protected function affectedRows($relation, $foreignKey, $foreignKeyIds)
    {
        $relationModel = $relation->getQuery()->getModel();
        $relationModel = new $relationModel();

        return $relationModel->withTrashed()->whereIn($foreignKey, $foreignKeyIds)->count();
    }
1069916
protected function belongsTo($class, $foreignKey): ?LightModel
    {
        $identifier = implode('_', [$class, $foreignKey]);

        if (! isset($this->_belongsTo[$identifier]))
        {
            if (! $this->getTable()->hasColumn($foreignKey))
            {
                throw new ColumnMissingException($this->getTableName() . ' does not have column: ' . $foreignKey);
            }

            $this->_belongsTo[$identifier] = $class::getOneByKey($this->$foreignKey);
        }

        return $this->_belongsTo[$identifier];
    }
58428
public function addForeignColumnName($foreignColumnName)
    {
        if (!is_string($foreignColumnName) || (strlen($foreignColumnName) <= 0)) {
            throw SchemaException::invalidForeignKeyForeignColumnName($this->getName());
        }

        $this->foreignColumnNames[] = $foreignColumnName;
    }
1119861
function DropForeignKey($table, $foreignKey)
    {
        $escaper = $this->GetEscaper();
        $query = 'ALTER TABLE ' . $escaper->EscapeIdentifier($table) . 
                ' DROP FOREIGN KEY ' . $escaper->EscapeIdentifier($foreignKey);
        $this->ExecuteQuery($query);
    }
688358
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
    {
        $this->output->createForeignKey($fkConstraint, $localTable);
    }
597615
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey)
    {
        $def = '';
        if ($foreignKey->getConstraint()) {
            $def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint());
        } else {
            $columnNames = [];
            foreach ($foreignKey->getColumns() as $column) {
                $columnNames[] = $this->quoteColumnName($column);
            }
            $def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')';
            $refColumnNames = [];
            foreach ($foreignKey->getReferencedColumns() as $column) {
                $refColumnNames[] = $this->quoteColumnName($column);
            }
            $def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')';
            if ($foreignKey->getOnDelete()) {
                $def .= ' ON DELETE ' . $foreignKey->getOnDelete();
            }
            if ($foreignKey->getOnUpdate()) {
                $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate();
            }
        }

        return $def;
    }
1321178
public function setPivotKeys($foreignKey, $otherKey)
    {
        $this->foreignKey = $foreignKey;

        $this->otherKey = $otherKey;

        return $this;
    }
18955
public function setPivotKeys($foreignKey, $relatedKey)
    {
        $this->foreignKey = $foreignKey;

        $this->relatedKey = $relatedKey;

        return $this;
    }
246046
public function getMappedLocalColumn($foreign)
    {
        $index = array_search($foreign, $this->foreignColumns);
        return $this->localColumns[$index];
    }
555088
public function setForeign($foreign)
    {
        if (!is_string($foreign) && null !== $foreign) {
            throw new \InvalidArgumentException('The attribute foreign on the class Attribute has to be string or null (' . gettype($foreign) . ('object' === gettype($foreign) ? ' ' . get_class($foreign) : '') . ' given).');
        }

        $this->foreign = $foreign;

        return $this;
    }