diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 128b0c309..29bd1fcb8 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2421,17 +2421,17 @@ class DboSource extends DataSource { $key = preg_replace('/\\x20(ASC|DESC).*/i', '', $key); } + $key = trim($key); + + if (is_object($model) && $model->isVirtualField($key)) { + $key = '(' . $this->__quoteFields($model->getVirtualField($key)) . ')'; + } + if (strpos($key, '.')) { $key = preg_replace_callback('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', array(&$this, '__quoteMatchedField'), $key); } - - $key = trim($key); - if (!preg_match('/\s/', $key) && !strpos($key,'.')) { - if (is_object($model) && $model->isVirtualField($key)) { - $key = '('.$this->__quoteFields($model->getVirtualField($key)).')'; - } else { - $key = $this->name($key); - } + if (!preg_match('/\s/', $key) && !strpos($key, '.')) { + $key = $this->name($key); } $key .= ' ' . trim($dir); $result[] = $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 b3b7030db..2ba412ab4 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4353,6 +4353,11 @@ class DboSourceTest extends CakeTestCase { $result = $this->db->order($order, 'ASC', $Article); $expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC'; $this->assertEqual($expected, $result); + + $order = array('Article.two', 'Article.this_moment'); + $result = $this->db->order($order, 'ASC', $Article); + $expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC'; + $this->assertEqual($expected, $result); } /**