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
for this expression:
WHERE activated_at IS NULL
try this (it's working):
->andWhere(['is', 'activated_at', new \yii\db\Expression('null')]),
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
$null = new Expression('NULL');
$query->andFilterWhere(['is not', 'asp_id', $null]);
OR
$query->andFilterWhere(['is', 'asp_id', $null]);
If i understand right you can use andWhere
->andWhere(['not', ['activated_at' => null]])
but andFilterWhere in execute where the related value is not null
from doc http://www.yiiframework.com/doc-2.0/yii-db-query.html
andFilterWhere() Adds an additional WHERE condition to the existing one but ignores empty operands.
// ...WHERE (`status` = 10) AND (`type` IS NULL) AND (`info` IS NOT NULL)
$query->where([
'status' => 10,
'type' => null,
])
->andWhere(['not', ['info' => null]]);