Skip to content

Commit

Permalink
Fixed bug in CakeSchema where it determines the field position.
Browse files Browse the repository at this point in the history
- Respective tests were added.
- Schema files will now have 'after' => 'previous_field' on it.
  • Loading branch information
renan committed Sep 16, 2011
1 parent 60981fc commit 707c0b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/cake_schema.php
Expand Up @@ -491,7 +491,7 @@ function compare($old, $new = null) {
} }
} }


if (isset($add[$table][$field])) { if (isset($tables[$table]['add'][$field]) && $field !== 'indexes' && $field !== 'tableParameters') {
$wrapper = array_keys($fields); $wrapper = array_keys($fields);
if ($column = array_search($field, $wrapper)) { if ($column = array_search($field, $wrapper)) {
if (isset($wrapper[$column - 1])) { if (isset($wrapper[$column - 1])) {
Expand Down
16 changes: 8 additions & 8 deletions cake/tests/cases/libs/model/cake_schema.test.php
Expand Up @@ -741,8 +741,8 @@ function testSchemaComparison() {
$expected = array( $expected = array(
'comments' => array( 'comments' => array(
'add' => array( 'add' => array(
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'after' => 'id'),
'title' => array('type' => 'string', 'null' => false, 'length' => 100), 'title' => array('type' => 'string', 'null' => false, 'length' => 100, 'after' => 'user_id'),
), ),
'drop' => array( 'drop' => array(
'article_id' => array('type' => 'integer', 'null' => false), 'article_id' => array('type' => 'integer', 'null' => false),
Expand All @@ -754,7 +754,7 @@ function testSchemaComparison() {
), ),
'posts' => array( 'posts' => array(
'add' => array( 'add' => array(
'summary' => array('type' => 'text', 'null' => 1), 'summary' => array('type' => 'text', 'null' => 1, 'after' => 'body'),
), ),
'drop' => array( 'drop' => array(
'tableParameters' => array(), 'tableParameters' => array(),
Expand Down Expand Up @@ -795,11 +795,11 @@ function testSchemaComparison() {
'ratings' => array( 'ratings' => array(
'add' => array( 'add' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'id'),
'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL), 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL, 'after' => 'foreign_key'),
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL), 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL, 'after' => 'model'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'value'),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'created'),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
) )
Expand Down

0 comments on commit 707c0b4

Please sign in to comment.