0

나는 동등하지 않은 조건을 얻을 수 없습니다. cancelled_by 필드가 null이므로 모든 데이터가 무시됩니다. cancelled_by 필드가 null 인 경우이 값은 Tutor과 동일하지 않습니다.은 cakephp3에서 작동하지 않습니다.

이 작은 오류로 인해 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); 
+1

평등 연산자는 일반적으로 SQL에서 null 값과 잘 상호 작용하지 않습니다. 아마도 'cancelled_by IS'=> NULL' 또는 'IS NOT'을 적절하게 사용하여 "OR"조건을 추가해야합니다. –

+0

이것은 PHP와는 관련이 없습니다. SQL 언어에서 'NULL'은 정의상 아무 것도 아닙니다. –

+0

내가 문제를 이해한다면 도움을 요청하지 않을 것이며, cakephp3에 게시하지 않을 것입니다. – jagguy

답변

2

'Lessons.cancelled_by !=' => 'Tutor'은 정확하지만 null 값으로는 작동하지 않습니다. 'Lessons.cancelled_by IS NOT' => 'NULL' 대신 NULL 값을 사용할 수 있습니다. 둘 다 사용할 수 있다고 생각합니다. 따라서 결과는 필요한 결과입니다 (cancelled_by! = '교사'및 cancelled_by IS NOT NULL).

-1

사용 -> notEq()

예를

$query = $articles->find() 
    ->where(function ($exp) { 
     return $exp 
      ->eq('author_id', 2) 
      ->eq('published', true) 
      ->notEq('spam', true) 
      ->gt('view_count', 10); 
    }); 

+1

어떻게하면 NULL 값으로 문제를 해결할 수 있습니까? 'notEq()'는 질문에 표시된 것과 똑같은 비교를 생성합니다. 즉,! = 연산자를 생성합니다. – ndm

0

Cakephp 3이 여기에 포스터에 의해 정답이었다 자세한 내용은 여기를 참조하세요. 그 사람이 여기에 대답을 할 수 있다면. 익명 연산자는 일반적으로 SQL에서 null 값과 잘 상호 작용하지 않습니다. 아마 'cancelled_by IS'=> NULL 또는 IS NOT으로 적절하게 "OR"조건을 추가해야합니다.