Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug in CakeSchema where it determines the field position.

- Respective tests were added.
- Schema files will now have 'after' => 'previous_field' on it.
  • Loading branch information...
commit 707c0b4130877c07967c210b07ec75995e05f818 1 parent 60981fc
@renan renan authored
View
2  cake/libs/model/cake_schema.php
@@ -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);
if ($column = array_search($field, $wrapper)) {
if (isset($wrapper[$column - 1])) {
View
16 cake/tests/cases/libs/model/cake_schema.test.php
@@ -741,8 +741,8 @@ 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),
@@ -754,7 +754,7 @@ function testSchemaComparison() {
),
'posts' => array(
'add' => array(
- 'summary' => array('type' => 'text', 'null' => 1),
+ 'summary' => array('type' => 'text', 'null' => 1, 'after' => 'body'),
),
'drop' => array(
'tableParameters' => array(),
@@ -795,11 +795,11 @@ 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')
)
Please sign in to comment.
Something went wrong with that request. Please try again.