Fixed bug in CakeSchema where it determines the field position.

- Respective tests were added.
- Schema files will now have 'after' => 'previous_field' on it.
This commit is contained in:
Renan Gonçalves 2011-09-16 15:28:28 +02:00
parent 7c87e9abc1
commit 4378bb6dc4
2 changed files with 9 additions and 9 deletions

View file

@ -481,7 +481,7 @@ class CakeSchema extends Object {
}
}
if (isset($add[$table][$field])) {
if (isset($tables[$table]['add'][$field]) && $field !== 'indexes' && $field !== 'tableParameters') {
$wrapper = array_keys($fields);
if ($column = array_search($field, $wrapper)) {
if (isset($wrapper[$column - 1])) {

View file

@ -779,8 +779,8 @@ class CakeSchemaTest extends CakeTestCase {
$expected = array(
'comments' => array(
'add' => array(
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'after' => 'id'),
'title' => array('type' => 'string', 'null' => false, 'length' => 100, 'after' => 'user_id'),
),
'drop' => array(
'article_id' => array('type' => 'integer', 'null' => false),
@ -792,7 +792,7 @@ class CakeSchemaTest extends CakeTestCase {
),
'posts' => array(
'add' => array(
'summary' => array('type' => 'text', 'null' => true),
'summary' => array('type' => 'text', 'null' => true, 'after' => 'body'),
),
'drop' => array(
'tableParameters' => array(),
@ -835,11 +835,11 @@ class CakeSchemaTest extends CakeTestCase {
'ratings' => array(
'add' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL),
'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL),
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'id'),
'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL, 'after' => 'foreign_key'),
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL, 'after' => 'model'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'value'),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'created'),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
)