[2.0] DDC-301 - Table Primary Key Columns should explicitly set to notnull => true.
This commit is contained in:
parent
7cf8d1ae52
commit
e500669165
@ -148,7 +148,14 @@ class Table extends AbstractAsset
|
||||
*/
|
||||
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
|
||||
$this->assertTrue($table->hasIndex('my_idx'));
|
||||
$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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user