Skip to content

Commit

Permalink
Merge pull request #234 from alex88/DBAL-392
Browse files Browse the repository at this point in the history
DBAL-392 Moving entity relationship doesn't move foreign key in mysql table
  • Loading branch information
beberlei committed Dec 23, 2012
2 parents b9ada57 + d7908fe commit aad1a94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Expand Up @@ -317,6 +317,10 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint
return true; return true;
} }


if (strtolower($key1->getForeignTableName()) != strtolower($key2->getForeignTableName())) {
return true;
}

if ($key1->onUpdate() != $key2->onUpdate()) { if ($key1->onUpdate() != $key2->onUpdate()) {
return true; return true;
} }
Expand Down
23 changes: 23 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Expand Up @@ -486,6 +486,29 @@ public function testTableUpdateForeignKey()
$this->assertEquals(1, count($tableDiff->changedForeignKeys)); $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() public function testTablesCaseInsensitive()
{ {
$schemaA = new Schema(); $schemaA = new Schema();
Expand Down

0 comments on commit aad1a94

Please sign in to comment.