Browse files

Fix bug in Index::overrules()

  • Loading branch information...
1 parent 4cfb32d commit 2cb22496a732029373d98ff9e4d54a7187ee9bb8 @beberlei beberlei committed Jun 26, 2011
Showing with 28 additions and 1 deletion.
  1. +13 −1 lib/Doctrine/DBAL/Schema/Index.php
  2. +15 −0 tests/Doctrine/Tests/DBAL/Schema/TableTest.php
View
14 lib/Doctrine/DBAL/Schema/Index.php
@@ -76,6 +76,16 @@ public function getColumns()
{
return $this->_columns;
}
+
+ /**
+ * Is the index neither unique nor primary key?
+ *
+ * @return bool
+ */
+ public function isSimpleIndex()
+ {
+ return !$this->_isPrimary && !$this->_isUnique;
+ }
/**
* @return bool
@@ -164,7 +174,9 @@ public function isFullfilledBy(Index $other)
*/
public function overrules(Index $other)
{
- if ($other->isPrimary() || $other->isUnique()) {
+ if ($other->isPrimary()) {
+ return false;
+ } else if ($this->isSimpleIndex() && $other->isUnique()) {
return false;
}
View
15 tests/Doctrine/Tests/DBAL/Schema/TableTest.php
@@ -406,6 +406,21 @@ public function testOverruleIndex()
$this->assertEquals(1, count($table->getIndexes()));
$this->assertFalse($table->hasIndex($index->getName()));
}
+
+ public function testPrimaryKeyOverrulesUniqueIndex()
+ {
+ $table = new Table("bar");
+ $table->addColumn('baz', 'integer', array());
+ $table->addUniqueIndex(array('baz'));
+
+ $table->setPrimaryKey(array('baz'));
+
+ $indexes = $table->getIndexes();
+ $this->assertEquals(1, count($indexes), "Table should only contain the primary key table index, not the unique one anymore, because it was overruled.");
+
+ $index = current($indexes);
+ $this->assertTrue($index->isPrimary());
+ }
/**
* @group DBAL-64

0 comments on commit 2cb2249

Please sign in to comment.