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 7c87e9a commit 4378bb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Model/CakeSchema.php
Expand Up @@ -481,7 +481,7 @@ public function compare($old, $new = null) {
}
}

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])) {
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Test/Case/Model/CakeSchemaTest.php
Expand Up @@ -779,8 +779,8 @@ public function testSchemaComparison() {
$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),
Expand All @@ -792,7 +792,7 @@ public function testSchemaComparison() {
),
'posts' => array(
'add' => array(
'summary' => array('type' => 'text', 'null' => true),
'summary' => array('type' => 'text', 'null' => true, 'after' => 'body'),
),
'drop' => array(
'tableParameters' => array(),
Expand Down Expand Up @@ -835,11 +835,11 @@ public function testSchemaComparison() {
'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')
)
Expand Down

0 comments on commit 4378bb6

Please sign in to comment.