Cakephp集团由和订单一起不工作

时间:2014-05-15 12:55:22

标签: cakephp group-by sql-order-by

我正在努力让员工及其发布详细信息的日期最长posting_from。 我的疑问是:

$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'),
              'group' => 'EmployeePersonal.id',
              'order' => 'EmployeePosting.posting_from DESC',
                       'recursive' => -1,
              'joins' => array(

                   array(
                      'table' => 'employee_postings',
                      'alias' => 'EmployeePosting',
                      'type' => 'LEFT',

                      'conditions' => array(
                          'EmployeePosting.employee_personal_id = EmployeePersonal.id',
                      )
                  ),
              )
          )
);

但上述查询显示最低posting_from值。为什么order在我的情况下工作?

1 个答案:

答案 0 :(得分:1)

一些逗号并准备就绪:

$emp = $this->EmployeePersonal ->find(
          'all',
          array(
             'joins' => array(
                   array(
                      'table' => 'employee_postings',
                      'alias' => 'EmployeePosting',
                      'type' => 'LEFT',
                      'conditions' => array(
                          'EmployeePosting.employee_personal_id = EmployeePersonal.id'
                      )
                  )
              ),
              'fields' => array('EmployeePersonal.*', 'PermanentDist.name','PresentDist.name','EmployeePosting.*','Designation.name','Department.name','Office.name'),
              'conditions' => $condition,
              //'order' => array('Designation.id'),
              'group' => 'EmployeePersonal.id',
              'order' => array(
                  'EmployeePosting.posting_from' => 'DESC'
              ),
              'recursive' => -1
        )
);