mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 03:22:39 +00:00
Fixing virtualFields used in order clauses where virtualField was supplied with model alias. Tests added. Refs #768
This commit is contained in:
parent
c98a82c61c
commit
7ed67e5959
2 changed files with 13 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue