Last active
July 31, 2020 08:24
-
-
Save sorokadima/abfcab04e1dfffe3bc4131c841da1bdc to your computer and use it in GitHub Desktop.
Yii is null MySQL Expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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