How to do IS NULL and IS NOT NULL with Yii 2 ActiveRecord?

后端 未结 5 2048
情话喂你
情话喂你 2021-02-12 10:22

I have a table which has a field `activated_at` timestamp NULL DEFAULT NULL, which means that it can contain a timestamp or it can be null and it\'s

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-12 11:02

    this solution check if column_name is empty or NULL

    WHERE (LENGTH(`column_name`) > 0)

    ->andWhere(['>', 'LENGTH(column_name)', 0]) //check if empty or null
    

    Another variant - check only for NULL

    WHERE column_name IS NOT NULL

    ->andWhere(['IS NOT', 'column_name', null]); // check on null
    

提交回复
热议问题