Skip to content

Commit

Permalink
Fixing order condition quoting to allow fields with - in them. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 25, 2011
1 parent b8e560b commit 532555b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -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()');
}

/**
Expand Down

0 comments on commit 532555b

Please sign in to comment.