我正在尝试查找用户输入的日期是否与数据库上的任何日期重叠。
我已经把 SQL 语句写下来了(可能需要一些调整,将测试),但我正在努力将它正确地放入 cakePHP。
我有什么
$result = $this->find('all', array(
'conditions' => array(
'OR' => array(
'AND' => array(
array('BoardroomBooking.start_time >=' => $this->data['BoardroomBooking']['start_time']),
array('BoardroomBooking.start_time <' => $this->data['BoardroomBooking']['start_time'])
),
'AND' => array(
array('BoardroomBooking.start_time <=' => $this->data['BoardroomBooking']['start_time']),
array('BoardroomBooking.start_time >' => $this->data['BoardroomBooking']['end_time'])
)
)
)
));
它创造了什么
SQL Query: SELECT `BoardroomBooking`.`id`, `BoardroomBooking`.`name`,
`BoardroomBooking`.`boardroom_id`, `BoardroomBooking`.`date`,
`BoardroomBooking`.`start_time`, `BoardroomBooking`.`end_time`,
`BoardroomBooking`.`notes`, `BoardroomBooking`.`recurrence_id`,
`BoardroomBooking`.`created`, `BoardroomBooking`.`modified`, `Boardroom`.`id`,
`Boardroom`.`name`, `Boardroom`.`created`, `Boardroom`.`modified` FROM
`intraweb_db`.`boardroom_bookings` AS `BoardroomBooking` LEFT JOIN
`intraweb_db`.`boardrooms` AS `Boardroom` ON (`BoardroomBooking`.`boardroom_id`
= `Boardroom`.`id`) WHERE ((`BoardroomBooking`.`start_time` <= '12:55:00') AND
(`BoardroomBooking`.`start_time` > '13:00:00'))
我想要的是
SQL Query: SELECT `BoardroomBooking`.`id`, `BoardroomBooking`.`name`,
`BoardroomBooking`.`boardroom_id`, `BoardroomBooking`.`date`,
`BoardroomBooking`.`start_time`, `BoardroomBooking`.`end_time`,
`BoardroomBooking`.`notes`, `BoardroomBooking`.`recurrence_id`,
`BoardroomBooking`.`created`, `BoardroomBooking`.`modified`, `Boardroom`.`id`,
`Boardroom`.`name`, `Boardroom`.`created`, `Boardroom`.`modified` FROM
`intraweb_db`.`boardroom_bookings` AS `BoardroomBooking` LEFT JOIN
`intraweb_db`.`boardrooms` AS `Boardroom` ON (`BoardroomBooking`.`boardroom_id`
= `Boardroom`.`id`) WHERE (`BoardroomBooking`.`start_time` >= '12:55:00' AND
`BoardroomBooking`.`start_time` < '12:55:00') OR (`BoardroomBooking`.`start_time`
<= '12:55:00') AND (`BoardroomBooking`.`start_time` > '13:00:00'))
我已经阅读了有关如何检索数据的文档,但是对于我的生活来说,它无法按照我想要的方式工作。