【发布时间】:2017-02-27 01:00:39
【问题描述】:
我无法让不等于条件起作用。发生的情况是它忽略了所有数据,因为cancelled_by 字段一直是null。如果cancelled_by 字段为null,则不等于不等于Tutor。
这个小错误让我损失了 5 天的错误数据。我犯了一个错误吗?一旦我删除了不等于条件,所有数据都按预期检索。
下面的 2 行是我使用的,但都没有用。
'Lessons.cancelled_by not like' => '%Tutor%'
'Lessons.cancelled_by !=' => 'Tutor'
$searchDate = date('Y-m-d');
$query3 = $this->find()
->contain([
'Tutors', 'Subjects', 'Students', 'Students.Guardians', 'XeroInvoices'
])
->select([
'Lessons.id', 'Lessons.lesson_date', 'Lessons.start_time', 'Lessons.end_time',
'Tutors.id', 'Tutors.first_name', 'Guardians.id', 'Tutors.last_name',
'Lessons.timesheet_status', 'Students.id', 'Students.first_name',
'Students.last_name', 'Students.has_credit', 'XeroInvoices.invoice_number',
'Guardians.guardian_email', 'Guardians.guardian_mobile',
'Guardians.guardian_last_name', 'Guardians.guardian_first_name',
'Lessons.due_date', 'Lessons.cancelled_by', 'Subjects.name', 'Lessons.revenue',
'Lessons.discount', 'Lessons.surcharge', 'Lessons.future_makeup_lesson_id',
'Lessons.cancelled_pastlesson_id'
])
->where([
'Lessons.due_date' => $searchDate,
'Lessons.lesson_inactive' => false,
'Students.has_credit like' => '%postpaid%',
'Lessons.cancelled_by !=' => 'Tutor'
])
->order([
'Guardians.id',
'Lessons.lesson_date' => 'ASC',
'Lessons.start_time' => 'ASC'
])
->hydrate(false);
【问题讨论】:
-
等式运算符通常不能与 SQL 中的 null 值很好地交互。您应该酌情使用
'cancelled_by IS' => NULL或IS NOT添加“OR”条件。 -
这与 PHP 无关。在 SQL 语言中,
NULL不等于任何定义。 -
如果我理解了这个问题,那么我就不会寻求帮助,我也不会在 cakephp3 中发布这个。
-
@jagguy 对不起,如果我冒犯了你,我唯一的目的是提供有关根本问题的信息。
标签: cakephp cakephp-3.0 nullable query-builder comparison-operators