Permalink
Browse files

Fixing virtualFields used in order clauses where virtualField was sup…

…plied with model alias. Tests added. Refs #768
  • Loading branch information...
1 parent c98a82c commit 7ed67e59598e71987168fba2db20362c9ffb4223 @markstory markstory committed May 31, 2010
@@ -2421,17 +2421,17 @@ function order($keys, $direction = 'ASC', $model = null) {
$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;
@@ -4353,6 +4353,11 @@ function testVirtualFieldsInOrder() {
$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);
}
/**

0 comments on commit 7ed67e5

Please sign in to comment.