Fixing virtualFields used in order clauses where virtualField was supplied with model alias. Tests added. Refs #768

This commit is contained in:
mark_story 2010-05-30 20:30:58 -04:00
parent c98a82c61c
commit 7ed67e5959
2 changed files with 13 additions and 8 deletions

View file

@ -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;

View file

@ -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);
}
/**