Commit b4dad07a authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-79 - Add Schema\Table::hasPrimaryKey() method.

parent 37186d98
......@@ -524,6 +524,16 @@ class Table extends AbstractAsset
return $this->getIndex($this->_primaryKeyName);
}
/**
* Check if this table has a primary key.
*
* @return bool
*/
public function hasPrimaryKey()
{
return ($this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName));
}
/**
* @param string $indexName
* @return bool
......
......@@ -416,4 +416,19 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('`bar`', $table->getQuotedName($mysqlPlatform));
$this->assertEquals('"bar"', $table->getQuotedName($sqlitePlatform));
}
/**
* @group DBAL-79
*/
public function testTableHasPrimaryKey()
{
$table = new Table("test");
$this->assertFalse($table->hasPrimaryKey());
$table->addColumn("foo", "integer");
$table->setPrimaryKey(array("foo"));
$this->assertTrue($table->hasPrimaryKey());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment