Permalink
Browse files

Added test and fix for DBAL-392 Moving entity relationship doesn't mo…

…ve foreign key in mysql table
  • Loading branch information...
1 parent 8fd4886 commit b84cda24335207d4e60afc88fa161317d94b6370 @alex88 alex88 committed with beberlei Nov 24, 2012
Showing with 27 additions and 0 deletions.
  1. +4 −0 lib/Doctrine/DBAL/Schema/Comparator.php
  2. +23 −0 tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
@@ -317,6 +317,10 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint
return true;
}
+ if (strtolower($key1->getForeignTableName()) != strtolower($key2->getForeignTableName())) {
+ return true;
+ }
+
if ($key1->onUpdate() != $key2->onUpdate()) {
return true;
}
@@ -486,6 +486,29 @@ public function testTableUpdateForeignKey()
$this->assertEquals(1, count($tableDiff->changedForeignKeys));
}
+ public function testMovedForeignKeyForeignTable()
+ {
+ $tableForeign = new Table("bar");
+ $tableForeign->addColumn('id', 'integer');
+
+ $tableForeign2 = new Table("bar2");
+ $tableForeign2->addColumn('id', 'integer');
+
+ $table1 = new Table("foo");
+ $table1->addColumn('fk', 'integer');
+ $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
+
+ $table2 = new Table("foo");
+ $table2->addColumn('fk', 'integer');
+ $table2->addForeignKeyConstraint($tableForeign2, array('fk'), array('id'));
+
+ $c = new Comparator();
+ $tableDiff = $c->diffTable($table1, $table2);
+
+ $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
+ $this->assertEquals(1, count($tableDiff->changedForeignKeys));
+ }
+
public function testTablesCaseInsensitive()
{
$schemaA = new Schema();

0 comments on commit b84cda2

Please sign in to comment.