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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With