Using Is NOT NULL in query builder

When building where clauses it's not that well documented how to use NOT and NULL .

Starting with a simple query:

    $post = Post::find()->all();
If we wanted to select all posts where the content had something in it
    $post = Post::find()
      ->where(['not',['content'=>null]])
      ->all();
Note the doubles set of square brackets, first before the 'not' and then around the parameters. So, that could also be
    $post = Post::find()
      ->where([ 'not',[ 'content'=>null, 'status' => 1 ]])
      ->all();
Which would equate to content is not null and status not equal 1.

Did you know you can hire me?

I take on projects of all sizes. From Consulting to large Development Projects.

If you're starting a new Yii project and would like some help to get setup and running or you need some help with a particular module or you just need someone to develop the whole dang thing, then just ask ...


Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com