mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix 'order' not working with a single expressions
This commit is contained in:
parent
668e7473b9
commit
4ae9f13dfd
2 changed files with 38 additions and 2 deletions
|
@ -3083,7 +3083,11 @@ class Model extends CakeObject implements CakeEventListener {
|
|||
$query['order'] = $this->order;
|
||||
}
|
||||
|
||||
if (is_object($query['order'])) {
|
||||
$query['order'] = array($query['order']);
|
||||
} else {
|
||||
$query['order'] = (array)$query['order'];
|
||||
}
|
||||
|
||||
if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
|
||||
$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
|
||||
*/
|
||||
|
@ -7445,6 +7445,38 @@ class ModelReadTest extends BaseModelTest {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue