mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge pull request #11472 from chinpei215/2.x-order-expression
[2.x] Fix 'order' not working with a single expressions
This commit is contained in:
commit
979eaeef5f
2 changed files with 38 additions and 2 deletions
|
@ -3083,7 +3083,11 @@ class Model extends CakeObject implements CakeEventListener {
|
||||||
$query['order'] = $this->order;
|
$query['order'] = $this->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_object($query['order'])) {
|
||||||
|
$query['order'] = array($query['order']);
|
||||||
|
} else {
|
||||||
$query['order'] = (array)$query['order'];
|
$query['order'] = (array)$query['order'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
|
if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
|
||||||
$event = new CakeEvent('Model.beforeFind', $this, array($query));
|
$event = new CakeEvent('Model.beforeFind', $this, array($query));
|
||||||
|
|
|
@ -7423,7 +7423,7 @@ class ModelReadTest extends BaseModelTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test find(count) with Db::expression
|
* Test find(count) with DboSource::expression
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -7445,6 +7445,38 @@ class ModelReadTest extends BaseModelTest {
|
||||||
$this->assertEquals(1, $result);
|
$this->assertEquals(1, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test 'order' with DboSource::expression
|
||||||
|
*/
|
||||||
|
public function testOrderWithDbExpressions() {
|
||||||
|
$this->loadFixtures('User');
|
||||||
|
|
||||||
|
$User = new User();
|
||||||
|
|
||||||
|
$results = $User->find('all', array(
|
||||||
|
'fields' => array('id'),
|
||||||
|
'recursive' => -1,
|
||||||
|
'order' => $this->db->expression('CASE id WHEN 4 THEN 0 ELSE id END'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
array(
|
||||||
|
'User' => array('id' => 4),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array('id' => 1),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array('id' => 2),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array('id' => 3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $results);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testFindMagic method
|
* testFindMagic method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue