Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write order and limit within cakephp joins array

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.

like image 336
Nitish Avatar asked Dec 05 '25 20:12

Nitish


1 Answers

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.

like image 155
Arun Jain Avatar answered Dec 08 '25 23:12

Arun Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!