I try to get the result of student (last insert).
I can easily fetch the record with mysql query like.
SELECT student.first_name,student.last_name,result.*
FROM result
join student
on student.student_id=result.student_id
WHERE result.id IN (
SELECT MAX(result.id) FROM result GROUP BY result.student_id
)
I try it to convert it in cake-php like this with pagination
$this->paginate = array(
'fields' => array(
'Student.first_name',
'Student.last_name',
'Result.*',
),
'joins' => array(
array(
'conditions' => array(
'Student.student_id = Result.student_id',
),
'table' => 'student',
'alias' => 'Student',
'type' => 'join',
),
),
'conditions' => array(
'Result.id' => array(
),
),
'limit'=>10,
'contain' => array(
'Student',
),
);
$data = $this->paginate('Result');