diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index b60b97e75..b3d493f52 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -280,19 +280,11 @@ class Comparator return true; } - if ($key1->hasOption('onUpdate') && $key->hasOption('onUpdate')) { - if ($key1->getOption('onUpdate') != $key2->getOption('onUpdate')) { - return true; - } - } else if ($key1->hasOption('onUpdate') != $key2->hasOption('onUpdate')) { + if ($key1->onUpdate() != $key2->onUpdate()) { return true; } - if ($key1->hasOption('onDelete') && $key2->hasOption('onDelete')) { - if ($key1->getOption('onDelete') != $key2->getOption('onDelete')) { - return true; - } - } else if ($key1->hasOption('onDelete') != $key2->hasOption('onDelete')) { + if ($key1->onDelete() != $key2->onDelete()) { return true; } diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 5ee351a55..398c72787 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -126,4 +126,39 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint { return $this->_options[$name]; } -} \ No newline at end of file + + /** + * Foreign Key onUpdate status + * + * @return string|null + */ + public function onUpdate() + { + return $this->_onEvent('onUpdate'); + } + + /** + * Foreign Key onDelete status + * + * @return string|null + */ + public function onDelete() + { + return $this->_onEvent('onDelete'); + } + + /** + * @param string $event + * @return string|null + */ + private function _onEvent($event) + { + if (isset($this->_options[$event])) { + $onEvent = strtoupper($this->_options[$event]); + if (!in_array($onEvent, array('NO ACTION', 'RESTRICT'))) { + return $onEvent; + } + } + return false; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 55461f078..4433ef924 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -31,7 +31,8 @@ use Doctrine\DBAL\Schema\Schema, Doctrine\DBAL\Schema\SchemaDiff, Doctrine\DBAL\Schema\TableDiff, Doctrine\DBAL\Schema\Comparator, - Doctrine\DBAL\Types\Type; + Doctrine\DBAL\Types\Type, + Doctrine\DBAL\Schema\ForeignKeyConstraint; /** * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -545,6 +546,15 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase $this->assertFalse($tableDiff); } + public function testCompareForeignKey_RestrictNoAction_AreTheSame() + { + $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION')); + $fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT')); + + $c = new Comparator(); + $this->assertFalse($c->diffForeignKey($fk1, $fk2)); + } + public function testDetectRenameColumn() { $tableA = new Table("foo");