Skip to content

Instantly share code, notes, and snippets.

@sorokadima
Last active July 31, 2020 08:24
Show Gist options
  • Save sorokadima/abfcab04e1dfffe3bc4131c841da1bdc to your computer and use it in GitHub Desktop.
Save sorokadima/abfcab04e1dfffe3bc4131c841da1bdc to your computer and use it in GitHub Desktop.
Yii is null MySQL Expression
<?php
protected function boolFilter($query, $field)
{
if ($this->$field === '0') {
return $query->andFilterWhere(['=', 'deposit', $this->$field])
->orFilterWhere(['is', $field, new \yii\db\Expression('null')]);
}
return $query->orFilterWhere(['=', $field, $this->$field]);
}
<?php
// new \yii\db\Expression('ISNULL(foo)'),
if ($this->foo === '0') {
$query->andFilterWhere(['is', 'foo', new \yii\db\Expression('null')])
->orFilterWhere(['=', 'foo', $this->foo]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment