From 4378bb6dc4c30758eb937bfc7486d03c3784ee1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Fri, 16 Sep 2011 15:28:28 +0200 Subject: [PATCH] Fixed bug in CakeSchema where it determines the field position. - Respective tests were added. - Schema files will now have 'after' => 'previous_field' on it. --- lib/Cake/Model/CakeSchema.php | 2 +- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Model/CakeSchema.php b/lib/Cake/Model/CakeSchema.php index 4ede1468316..c7dbd92c851 100644 --- a/lib/Cake/Model/CakeSchema.php +++ b/lib/Cake/Model/CakeSchema.php @@ -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])) { diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index e7f8b9dba8e..0de6c7d3d23 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -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), @@ -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(), @@ -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') )