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 c125e22 commit d7908feeb830ac006830422845b56e940a4ede5a @alex88 alex88 committed 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
View
4 lib/Doctrine/DBAL/Schema/Comparator.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;
}
View
23 tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
@@ -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 d7908fe

Please sign in to comment.