1
0
mirror of synced 2024-12-13 06:46:03 +03:00

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

This commit is contained in:
beberlei 2010-02-04 18:23:38 +00:00
parent 7cf8d1ae52
commit e500669165
2 changed files with 20 additions and 1 deletions

View File

@ -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;
}
/**

View File

@ -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());
}
}