Commit bcbc3a21 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-207' into 2.2

parents 083d68d9 53a671e4
......@@ -89,6 +89,14 @@ class RemoveNamespacedAssets implements Visitor
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
{
// The table may already be deleted in a previous
// RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
// point to nowhere.
if ( ! $this->schema->hasTable($fkConstraint->getForeignTableName())) {
$localTable->removeForeignKey($fkConstraint->getName());
return;
}
$foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName());
if ( ! $foreignTable->isInDefaultNamespace($this->schema->getName()) ) {
$localTable->removeForeignKey($fkConstraint->getName());
......
......@@ -37,6 +37,29 @@ class RemoveNamespacedAssetsTest extends \PHPUnit_Framework_TestCase
$config->setName("test");
$schema = new Schema(array(), array(), $config);
$fooTable = $schema->createTable("foo.bar");
$fooTable->addColumn('id', 'integer');
$testTable = $schema->createTable("test.test");
$testTable->addColumn('id', 'integer');
$testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
$schema->visit(new RemoveNamespacedAssets());
$sql = $schema->toSql(new MySqlPlatform());
$this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
}
/**
* @group DBAL-204
*/
public function testCleanupForeignKeysDifferentOrder()
{
$config = new SchemaConfig;
$config->setName("test");
$schema = new Schema(array(), array(), $config);
$testTable = $schema->createTable("test.test");
$testTable->addColumn('id', 'integer');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment