Commit e5006691 authored by beberlei's avatar beberlei

[2.0] DDC-301 - Table Primary Key Columns should explicitly set to notnull => true.

parent 7cf8d1ae
...@@ -148,7 +148,14 @@ class Table extends AbstractAsset ...@@ -148,7 +148,14 @@ class Table extends AbstractAsset
*/ */
public function setPrimaryKey(array $columns, $indexName = false) public function setPrimaryKey(array $columns, $indexName = false)
{ {
return $this->_createIndex($columns, $indexName ?: "primary", true, true); $primaryKey = $this->_createIndex($columns, $indexName ?: "primary", true, true);
foreach ($columns AS $columnName) {
$column = $this->getColumn($columnName);
$column->setNotnull(true);
}
return $primaryKey;
} }
/** /**
......
...@@ -341,4 +341,16 @@ class TableTest extends \PHPUnit_Framework_TestCase ...@@ -341,4 +341,16 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($table->hasIndex('my_idx')); $this->assertTrue($table->hasIndex('my_idx'));
$this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); $this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns());
} }
public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull()
{
$table = new Table("foo");
$column = $table->createColumn("id", 'integer', array('notnull' => false));
$this->assertFalse($column->getNotnull());
$table->setPrimaryKey(array('id'));
$this->assertTrue($column->getNotnull());
}
} }
\ 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