public function addForeignKey(ForeignKey $foreignKey)
    {
        if ($this->hasForeignKey($foreignKey->getName())) {
            throw SchemaException::tableForeignKeyAlreadyExists($this->getName(), $foreignKey->getName());
        }

        foreach ($foreignKey->getLocalColumnNames() as $columnName) {
            if (!$this->hasColumn($columnName)) {
                throw SchemaException::tableColumnDoesNotExist($this->getName(), $columnName);
            }
        }

        if ($this->hasSchema()) {
            foreach ($foreignKey->getForeignColumnNames() as $columnName) {
                if (!$this->getSchema()->getTable($foreignKey->getForeignTableName())->hasColumn($columnName)) {
                    throw SchemaException::tableColumnDoesNotExist($foreignKey->getForeignTableName(), $columnName);
                }
            }
        }

        $this->foreignKeys[$foreignKey->getName()] = $foreignKey;
    }
public function addForeignKey(ForeignKey $foreignKey)
    {
        if ($this->hasForeignKey($foreignKey->getName())) {
            throw SchemaException::tableForeignKeyAlreadyExists($this->getName(), $foreignKey->getName());
        }

        foreach ($foreignKey->getLocalColumnNames() as $columnName) {
            if (!$this->hasColumn($columnName)) {
                throw SchemaException::tableColumnDoesNotExist($this->getName(), $columnName);
            }
        }

        if ($this->hasSchema()) {
            foreach ($foreignKey->getForeignColumnNames() as $columnName) {
                if (!$this->getSchema()->getTable($foreignKey->getForeignTableName())->hasColumn($columnName)) {
                    throw SchemaException::tableColumnDoesNotExist($foreignKey->getForeignTableName(), $columnName);
                }
            }
        }

        $this->foreignKeys[$foreignKey->getName()] = $foreignKey;
    }
public function addForeignKey ( ForeignKey $ foreignKey ) { if ( $ this -> hasForeignKey ( $ foreignKey -> getName ( ) ) ) { throw SchemaException :: tableForeignKeyAlreadyExists ( $ this -> getName ( ) , $ foreignKey -> getName ( ) ) ; } foreach ( $ foreignKey -> getLocalColumnNames ( ) as $ columnName ) { if ( ! $ this -> hasColumn ( $ columnName ) ) { throw SchemaException :: tableColumnDoesNotExist ( $ this -> getName ( ) , $ columnName ) ; } } if ( $ this -> hasSchema ( ) ) { foreach ( $ foreignKey -> getForeignColumnNames ( ) as $ columnName ) { if ( ! $ this -> getSchema ( ) -> getTable ( $ foreignKey -> getForeignTableName ( ) ) -> hasColumn ( $ columnName ) ) { throw SchemaException :: tableColumnDoesNotExist ( $ foreignKey -> getForeignTableName ( ) , $ columnName ) ; } } } $ this -> foreignKeys [ $ foreignKey -> getName ( ) ] = $ foreignKey ; }
Adds a foreign key to the table.

@param \Fridge\DBAL\Schema\ForeignKey $foreignKey The foreign key to add.

@throws \Fridge\DBAL\Exception\SchemaException If the foreign key already exist, if a local column does not
exist or if a foreign column does not exist.
Adds a foreign key to the table .