0

私はcould notが動作するためには等しくない条件を得る。 cancelled_byフィールドがnullであるため、すべてのデータが無視されます。 cancelled_byフィールドがnullの場合、それはTutorと等しくないとは限りません。はcakephp3でisntと同じではない

この小さなエラーで5日間の間違ったデータが表示されました。私が作っている間違いはありますか? not equals条件を削除すると、すべてのデータが期待どおりに取得されました。

以下の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

は正しいですが、null値では機能しません。 'Lessons.cancelled_by IS NOT' => 'NULL'はNULL値の代わりに機能します。私はあなたが両方を使うことができると思います。だから、結果は必要な結果だけです(cancelled_by!= 'Tutor' AND 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); 
    }); 

読むCakephp 3

+1

これはどのようにして 'NULL'値の問題を解決するのでしょうか? 'notEq()'は質問に示されているものとまったく同じ比較を生成します。すなわち、 '!='演算子を生成します。 – ndm

0

これは、ここで、ポスターによる正解でした。その人が答えをここに置くことができるならば、一般的には、演算子はSQLのヌル値とうまく対話しません。おそらく、 'cancelled_by IS' => NULL、またはIS NOTと適切に「OR」条件を追加する必要があります。

関連する問題