如何在cakephp连接数组中写入顺序和限制 [英] How to write order and limit within cakephp joins array
本文介绍了如何在cakephp连接数组中写入顺序和限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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
。
posting_from ,您必须使用
'group_by'=> 'employee_personal_id'
而不是'limit'=> '1'
和'order'=> 'EmployeePosting.posting_from DESC'
在同一数组中将保持不变。 I have a join in cakephp as below:
$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',
)
),
)
)
);
But the lines
'order' => 'EmployeePosting.posting_from DESC',
'limit' => 1,
are not working ! That means though I was expecting to get last newest posting_from
value, I am getting all the values ! Where I am doing wrong ? I think I have written the order
limit
in wrong place.
解决方案
To get last newest posting_from
you must use 'group_by' => 'employee_personal_id'
instead of 'limit' => '1'
and 'order' => 'EmployeePosting.posting_from DESC'
will remain the same in the same array.
这篇关于如何在cakephp连接数组中写入顺序和限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文