【问题标题】:CakePHP find conditions generate SQL "WHERE ... AND 1"CakePHP 查找条件生成 SQL "WHERE ... AND 1"
【发布时间】:2011-06-13 12:31:08
【问题描述】:

这是我的代码:

    $attendances = $this->Pupil->Attendance->find('all',
        array(
            'conditions'=>array(
                'Pupil.group_id'=>$group,
                'Attendance.date' >= $start,
                'Attendance.date' <= $end
                )
            )
        )
    );

这是生成的 SQL:

SELECT [many different fields from a few tables] WHERE `Pupil`.`group_id` = 7 AND 1

$start 的值为 2011-06-06,end 为 2011-06-10(在视图中使用 debug() 验证)。

为什么 Cake 会生成条件“AND 1”,而忽略了我的条件?

感谢阅读!

【问题讨论】:

    标签: cakephp cakephp-1.3 cakephp-model


    【解决方案1】:

    好的,今天我的速度非常慢,为侮辱大家的智商道歉。

    当然,问题在于 >= 和

    对于任何有类似脑死亡时刻的人来说,正确的代码是

        $attendances = $this->Pupil->Attendance->find('all',
            array(
                'conditions'=>array(
                    'Pupil.group_id'=>$group,
                    'AND'=>array(
                        'Attendance.date >=' => $start,
                        'Attendance.date <=' => $end
                    )
                )
            )
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 2016-11-18
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      相关资源
      最近更新 更多