我加入了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
写在错误的位置。
答案 0 :(得分:2)
要获得最新的posting_from
,您必须使用'group_by' => 'employee_personal_id'
代替'limit' => '1'
而'order' => 'EmployeePosting.posting_from DESC'
在同一个数组中保持不变。