我试着得到学生的结果(最后一次插入)。
我可以使用mysql查询轻松获取记录,如。
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
)
我尝试用像分页这样的蛋糕-phc转换它
$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');
答案 0 :(得分:0)
请试试这个
$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 IN ( SELECT MAX(result.id) FROM result GROUP BY result.student_id )
),
'limit'=>10
);
$data = $this->paginate('Result');