如何在cakephp连接数组中编写顺序和限制

时间:2014-05-15 11:05:59

标签: cakephp join limit

我加入了cakephp如下:

$emp = $this->EmployeePersonal ->find(
          'all',
          array(
              'fields' => array('EmployeePersonal.*', 'PermanentDist.name','PresentDist.name','EmployeePosting.*','Designation.name','Department.name','Office.name' ),
              'conditions' => $condition,
              'order' => array('Designation.id'),
              'recursive' => -1,
              'joins' => array(
                          array(
                                   .................
                                   .................
                           ),

                   array(
                      'table' => 'employee_postings',
                      'alias' => 'EmployeePosting',
                      'type' => 'LEFT',
                      'order' => 'EmployeePosting.posting_from DESC',
                      'limit' => 1,
                      'conditions' => array(
                          'EmployeePosting.employee_personal_id = EmployeePersonal.id',
                      )
                  ),
              )
          )
);

但行

'order' => 'EmployeePosting.posting_from DESC',
'limit' => 1,

不能正常工作!这意味着虽然我期望得到最新的posting_from值,但我得到了所有的价值!我在哪里做错了?我想我已将order limit写在错误的位置。

1 个答案:

答案 0 :(得分:2)

要获得最新的posting_from,您必须使用'group_by' => 'employee_personal_id'代替'limit' => '1''order' => 'EmployeePosting.posting_from DESC'在同一个数组中保持不变。