Returns the list of cross foreign keys.

@return CrossForeignKeys[]
332054
public function getCrossFks()
    {
        $crossFks = [];
        foreach ($this->referrers as $refFK) {
            if ($refFK->getTable()->isCrossRef()) {
                $crossFK = new CrossForeignKeys($refFK, $this);
                foreach ($refFK->getOtherFks() as $fk) {
                    if ($fk->isAtLeastOneLocalPrimaryKeyIsRequired() &&
                        $crossFK->isAtLeastOneLocalPrimaryKeyNotCovered($fk)) {
                        $crossFK->addCrossForeignKey($fk);
                    }
                }
                if ($crossFK->hasCrossForeignKeys()) {
                    $crossFks[] = $crossFK;
                }
            }
        }

        return $crossFks;
    }
1100676
public function listGlobalActions()
    {
        $listGlobalActions = [];

        foreach ($this->listGlobalActions as $listGlobalAction) {
            $listGlobalActions[] = $this->getAction($listGlobalAction);
        }

        return $listGlobalActions;
    }
959375
protected function getAliasedPivotColumns()
    {
        $defaults = array($this->foreignKey, $this->otherKey);

        $columns = array();

        foreach (array_merge($defaults, $this->pivotColumns) as $column) {
            $columns[] = $this->table.'.'.$column.' as pivot_'.$column;
        }

        return array_unique($columns);
    }
767271
public function isForeignPrimaryKey()
    {
        $lfmap = $this->getLocalForeignMapping();
        $foreignTable = $this->getForeignTable();

        $foreignPKCols = array();
        foreach ($foreignTable->getPrimaryKey() as $fPKCol) {
            $foreignPKCols[] = $fPKCol->getName();
        }

        $foreignCols = array();
        foreach ($this->getLocalColumns() as $colName) {
            $foreignCols[] = $foreignTable->getColumn($lfmap[$colName])->getName();
        }

        return ((count($foreignPKCols) === count($foreignCols)) && !array_diff($foreignPKCols, $foreignCols));
    }
942512
protected function getTableForeignKeys(): array
    {
        $data = [];

        $fks = $this->db->schema->getTableForeignKeys($this->tableName, true);

        /* @var $fk ForeignKeyConstraint */
        foreach ($fks as $fk) {
            $data[$fk->name] = new TableForeignKey([
                'name' => $fk->name,
                'columns' => $fk->columnNames,
                'refTable' => $fk->foreignTableName,
                'refColumns' => $fk->foreignColumnNames,
                'onDelete' => $fk->onDelete,
                'onUpdate' => $fk->onUpdate,
            ]);
        }

        return $data;
    }
70931
public function alteredForeignKeys(): array
    {
        $difference = [];

        foreach ($this->current->getForeignKeys() as $name => $foreignKey) {
            if (!$this->initial->hasForeignKey($foreignKey->getColumn())) {
                //Added into schema
                continue;
            }

            $initial = $this->initial->findForeignKey($foreignKey->getColumn());
            if (!$foreignKey->compare($initial)) {
                $difference[] = [$foreignKey, $initial];
            }
        }

        return $difference;
    }
467878
private function getForeignKeyColumns()
    {
        $foreignKeyColumns = [];
        foreach ($this->getForeignKeys() as $foreignKey) {
            $foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns());
        }

        return $this->filterColumns($foreignKeyColumns);
    }
1034232
public function getLocalPrimaryKeys()
    {
        $cols = [];
        $localCols = $this->getLocalColumnObjects();

        foreach ($localCols as $localCol) {
            if ($localCol->isPrimaryKey()) {
                $cols[] = $localCol;
            }
        }

        return $cols;
    }
1166951
public function getAllLocalForeignKeys()
    {
        $columns = array();
        foreach ($this->getColumns() as $column) {
            foreach ($column->getLocalForeignKeys() as $foreignKey) {
                if (array_key_exists($foreignKey->getId(), $columns)) {
                    continue;
                }
                $columns[$foreignKey->getId()] = $foreignKey;
            }
        }

        return $columns;
    }
1168775
protected function collectForeignKeys()
    {
        $keys = [];

        foreach ($this->info->relations as $relation) {

            if ( ! in_array(
                $relation->type,
                [ RelationType::BELONGS_TO, RelationType::MORPH_TO, RelationType::BELONGS_TO_THROUGH ]
            )) {
                continue;
            }

            $keys = array_merge($keys, $relation->foreign_keys);
        }

        return $keys;
    }
750919
protected function getAllForeignKeysOrderedByTable()
    {
        $results = $this->dataBase->getAllForeignKeys();
        $results = ArrayHelpers::orderArrayByValue($results, 'TABLE_NAME');

        return $results;
    }
784259
protected function fetchPrimaryKeys(): array
    {
        $query = "SHOW INDEXES FROM {$this->driver->identifier($this->getName())}";

        $primaryKeys = [];
        foreach ($this->driver->query($query) as $index) {
            if ($index['Key_name'] == 'PRIMARY') {
                $primaryKeys[] = $index['Column_name'];
            }
        }

        return $primaryKeys;
    }
1042424
protected function getForeignKeysMigrations($new = [], $old = [])
    {
        if (empty($new['tables'])) {
            return [];
        }
        $output = [];
        foreach ($new['tables'] as $tableId => $newTable) {
            if ($newTable['table']['table_name'] === $this->options['default_migration_table']) {
                continue;
            }
            $oldTable = $old['tables'][$tableId];

            if (!empty($oldTable['foreign_keys'])) {
                foreach ($oldTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($newTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyRemove($tableId, $fkName);
                    }
                }
            }
            if (!empty($newTable['foreign_keys'])) {
                foreach ($newTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($oldTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyCreate($tableId, $fkName);
                    }
                }
            }
        }

        return $output;
    }
833092
protected function getGenericForeignKeys(array $foreignKeys)
    {
        $genericForeignKeys = array();

        foreach ($foreignKeys as $foreignKey) {
            $name = $foreignKey['name'];

            if (!isset($genericForeignKeys[$name])) {
                $genericForeignKeys[$name] = new ForeignKey(
                    $foreignKey['name'],
                    array($foreignKey['local_column_name']),
                    $foreignKey['foreign_table_name'],
                    array($foreignKey['foreign_column_name']),
                    $foreignKey['on_delete'],
                    $foreignKey['on_update']
                );
            } else {
                $genericForeignKeys[$name]->addLocalColumnName($foreignKey['local_column_name']);
                $genericForeignKeys[$name]->addForeignColumnName($foreignKey['foreign_column_name']);
            }
        }

        return array_values($genericForeignKeys);
    }
782641
public function columnKeys()
    {
        $columnKeys = [];

        foreach ($this->columns() as $key => $column) {
            if (is_string($key)) {
                $columnKeys[] = $key;
            } elseif (str_contains($column, '.')) {
                list($table, $columnKey) = explode('.', $column);
                $columnKeys[]            = $columnKey;
            } else {
                $columnKeys[] = $column;
            }
        }

        return $columnKeys;
    }
1350877
protected function getForeignKeyAttributesFromNonLoadedRelation(string $relation): array
    {
        $keys = $this->entityMap->getLocalKeys($relation);

        // We'll treat single and composite keys (polymorphic) the same way.
        if (!is_array($keys)) {
            $keys = [$keys];
        }

        $foreignKey = [];

        foreach ($keys as $key) {
            $foreignKey[$key] = $this->getEntityAttribute($key);
        }

        return $foreignKey;
    }
159477
public function getForeignLocalMapping()
    {
        $h = array();
        for ($i = 0, $size = count($this->localColumns); $i < $size; $i++) {
            $h[$this->foreignColumns[$i]] = $this->localColumns[$i];
        }

        return $h;
    }