From 532555b94b7205a19fc234db1fd2ae39c88e1c76 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 24 Mar 2011 22:28:11 -0400 Subject: [PATCH] Fixing order condition quoting to allow fields with - in them. Fixes #1599 --- cake/libs/model/datasources/dbo_source.php | 2 +- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index b610ee12137..abc75372d9a 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2439,7 +2439,7 @@ function order($keys, $direction = 'ASC', $model = null) { } if (strpos($key, '.')) { - $key = preg_replace_callback('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', array(&$this, '__quoteMatchedField'), $key); + $key = preg_replace_callback('/([a-zA-Z0-9_-]{1,})\\.([a-zA-Z0-9_-]{1,})/', array(&$this, '__quoteMatchedField'), $key); } if (!preg_match('/\s/', $key) && !strpos($key, '.')) { $key = $this->name($key); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 924e7256d9a..dfc432c916b 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -3512,6 +3512,10 @@ function testOrderParsing() { $result = $this->testDb->order(array('Property.sale_price IS NULL')); $expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC'; $this->assertEqual($result, $expected); + + $result = $this->testDb->order(array('Export.column-name' => 'ASC')); + $expected = ' ORDER BY `Export`.`column-name` ASC'; + $this->assertEqual($result, $expected, 'Columns with -s are not working with order()'); } /**