【发布时间】:2013-12-13 17:00:58
【问题描述】:
我正在使用 CakePHP,我已经阅读了 the documentation 关于检索数据的内容,它清楚地表明多个 ORDER BYs 是可能的。但是,我无法让它工作。它只适用于一个,但是当我将它更改为具有两个字符串的数组时,似乎都不适用。我做错了什么?
private function _bundle_users( $report ) {
$this->loadModel("User");
$conditions = array(
'ReportsUser.report_id' => $report['Report']['id']
);
//$order = 'ReportsUser.created DESC'; //THIS WORKS FINE
$order = array( //THIS SEEMS TO RESULT IN BOTH GETTING IGNORED
'ReportsUser.created DESC',
'User.last_name ASC',
);
$this->User->bindModel(array('hasOne' => array('ReportsUser')), false);
$this->paginate = array('conditions'=>$conditions, 'contain'=>array('ReportsUser', 'Attempt'=>array('order' => 'Attempt.created DESC'), 'Tag', 'Resume', 'School'),
'order'=>$order
);
$users = $this->Paginate('User');
return $users;
}
我认为我正在做与this example 完全相同的事情,但bindModel() 除外。也许这是一个相关的线索。
更新1
这按预期工作:$order = 'ReportsUser.created DESC';
但这被忽略了:$order = array('ReportsUser.created DESC');
似乎数组语法是问题的一部分。
更新2
当我使用 key => value 格式时,数组语法也会被忽略:'ReportsUser.created' => 'DESC'
更新3 感谢@Leonard,this 有效,尽管文档说了什么:
$order = 'ReportsUser.created DESC, User.last_name ASC';
【问题讨论】:
-
瞪眼,吃蛋糕的人。
-
根据文档,这不是要走的路,但是您是否尝试过:
$order = 'ReportsUser.created DESC, User.last_name ASC';? -
@Leonardo 哇!这完全不是它应该如何工作,但它可以。是什么让你产生了尝试的想法?
-
@SDP 只是 SQL 逻辑,我会添加它作为答案。我很高兴它成功了......
标签: php mysql sql cakephp cakephp-2.0