/** * @param Table $localTable * @param ForeignKeyConstraint $fkConstraint */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { if (strlen($fkConstraint->getName()) == 0) { throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint); } $this->_constraints[] = $this->_platform->getDropForeignKeySql($fkConstraint->getName(), $localTable->getName()); }
/** * Drops a foreign key from a table. * * @param ForeignKeyConstraint|string $table The name of the table with the foreign key. * @param Table|string $name The name of the foreign key. * @return boolean $result */ public function dropForeignKey($foreignKey, $table) { $this->_execSql($this->_platform->getDropForeignKeySql($foreignKey, $table)); }
/** * @param AbstractPlatform $platform * @param bool $saveMode * @return array */ protected function _toSql(AbstractPlatform $platform, $saveMode = false) { $sql = array(); if ($platform->supportsForeignKeyConstraints() && $saveMode == false) { foreach ($this->orphanedForeignKeys as $orphanedForeignKey) { $sql[] = $platform->getDropForeignKeySql($orphanedForeignKey, $orphanedForeignKey->getLocalTableName()); } } if ($platform->supportsSequences() == true) { foreach ($this->changedSequences as $sequence) { $sql[] = $platform->getDropSequenceSql($sequence); $sql[] = $platform->getCreateSequenceSql($sequence); } if ($saveMode === false) { foreach ($this->removedSequences as $sequence) { $sql[] = $platform->getDropSequenceSql($sequence); } } foreach ($this->newSequences as $sequence) { $sql[] = $platform->getCreateSequenceSql($sequence); } } foreach ($this->newTables as $table) { $sql = array_merge($sql, $platform->getCreateTableSql($table, AbstractPlatform::CREATE_FOREIGNKEYS | AbstractPlatform::CREATE_INDEXES)); } if ($saveMode === false) { foreach ($this->removedTables as $table) { $sql[] = $platform->getDropTableSql($table); } } foreach ($this->changedTables as $tableDiff) { $sql = array_merge($sql, $platform->getAlterTableSql($tableDiff)); } return $sql; }