CakePHP find conditions generate SQL "WHERE ... AND 1"
Here's my code:
$attendances = $this->Pupil->Attendance->find('all',
array(
'conditions'=>array(
'Pupil.group_id'=>$group,
'Attendance.date' >= $start,
'Attendance.date' <= $end
)
)
)
);
Here's the SQL that ge开发者_高级运维ts generated:
SELECT [many different fields from a few tables] WHERE `Pupil`.`group_id` = 7 AND 1
The value of $start is 2011-06-06 and end is 2011-06-10 (verified by using debug() in the view).
Why is Cake generating the condition "AND 1", and omitting my conditions?
Thanks for reading!
OK, I'm extremely slow today and I apologise for insulting everyone's intelligence.
The problem, of course, is that >= and <= are not inside the quotes.
The correct code, for anyone who has a similarly braindead moment, is
$attendances = $this->Pupil->Attendance->find('all',
array(
'conditions'=>array(
'Pupil.group_id'=>$group,
'AND'=>array(
'Attendance.date >=' => $start,
'Attendance.date <=' => $end
)
)
)
);
精彩评论