0

我正在对模型进行查找,如下所示,但是生成的 SQL 是错误的,因此我得到了不正确的结果。

$bookings = $this->Booking->find('all', array(
    'conditions' => array(
        'Booking.created BETWEEN ? AND ?' => array(
            date('Y-m-d H:i:s', strtotime('-24 hours')),
            date('Y-m-d H:i:s', strtotime('-12 hours'))
        ),
        'OR' => array(
            'Booking.payment_status' => 3,
            'Booking.payment_status' => 2
        )
    )
));

此查找生成的 WHERE 条件是(如 cake debugkit 所示)

WHERE `Booking`.`created` BETWEEN '2013-03-27 11:01:57' AND '2013-03-27 23:01:57' AND `Booking`.`payment_status` = 2

我试图创造的条件是

WHERE `Booking`.`created` BETWEEN '2013-03-27 11:01:57' AND '2013-03-27 23:01:57' AND (`Booking`.`payment_status` = 2 OR `Booking`.`payment_status` = 3)

任何想法我在这里做错了什么。快速帮助将不胜感激。谢谢!

4

1 回答 1

0

一个 PHP 初学者经常犯的错误——在数组中多次使用一个键:

    'OR' => array(
        'Booking.payment_status' => 3,
        'Booking.payment_status' => 2
    )

它应该读

    'OR' => array(
        array('Booking.payment_status' => 3),
        array('Booking.payment_status' => 2)
    )
于 2013-03-28T10:15:36.053 回答