Ticket #1125 (closed enhancement: fixed)
Doctrine_Migration::createTable() inconsistent with Doctrine_Record::hasColumn()
| Reported by: | hobodave | Owned by: | jwage |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | Migrations | Version: | 0.11.0 |
| Keywords: | createTable primary | Cc: | |
| Has Test: | no | Status: | Pending Core Response |
| Has Patch: | no |
Description
There is an undocumented (seemingly) inconsistency between the way a primary key is identified for a table in Doctrine_Record:hasColumn() and Doctrine_Migration::createTable().
When using Doctrine_Record you can specify a column as primary using the following syntax:
$this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
However trying to use the following, intuitive, syntax in Doctrine_Migration::createTable() does not work:
public function up()
{
$fields = array('id' => array(
'type' => 'integer',
'length' => 4,
'notnull' => true,
'autoincrement' => true,
'primary' => true
),
'name' => array(
'type' => 'string',
'length' => 255
),
'description' => array(
'type' => 'string',
'length' => 31
),
'ticket_id' => array(
'type' => 'integer',
'length' => 4
),
'filetype' => array(
'type' => 'string',
'length' => 31
),
'filesize' => array(
'type' => 'integer',
'length' => 4
),
'content' => array(
'type' => 'blob',
'length' => 8388607
));
$options = array('type' => 'INNODB',
'charset' => 'utf8');
$this->createTable($this->tableName, $fields, $options);
}
Note the specification of the 'id' column as Primary in the $fields array. Attempting to use this syntax results in a SQLSTATE Exception, because the PRIMARY sql specifier is never generated. Digging through the code showed me that Doctrine_Migration expects the primary key to be identified in the $options array as follows:
$options = array('type' => 'INNODB',
'charset' => 'utf8',
'primary' => array('id'));
Is this intentional, or an oversight? Does it make sense to have the formats consistent?