In Yii 1.1.*, how to find all data (via CActiveRecord implementation) where an attributes is NULL, kinda like:
Foo::model()->findAllByAttributes(['bar' => 'baz', 'qux' => [null, '']]);
It DOES NOT work because it produces query:
WHERE (bar = 'baz') AND (qux IN (, ''))
I want to find all Foo records where:
"bar"field equals with"baz"ANDquxfieldIS NULLor equals with empty string
I can do it with findAll, but how about if I want to use findAllByAttributes method? Thanks.
You can pass the condition for
quzas an additional parameter intofindAllByAttributes:You can't use
INwithnullvalues unless you replaceCDbCommandBuilderwith your own implementation.CActiveRecord::findAllByAttributescallsCDbCommandBuilder::createColumnCriteriawhich in turn callsCDbCommandBuilder::createInConditionif the column values are an array.From the source code values are cast into the column type and quoted afterwards and passed through
imploderesulting in thenullbeing treated as php'snullnot mysql'snull: