Hi, i’m having an unexpected result with a query in the search function of a searchmodel.
This code
$query->joinWith('fields_a fa');
$query->andFilterWhere(
['or',
['not',['fa.type' => $this->notConnectedTo]],
'fa.type is NULL',
]);
Executes this query (correct)
SELECT `anag`.* FROM `anag` LEFT JOIN `fields_a` `fa` ON `anag`.`id` = `fa`.`field`
WHERE (`archived`=0) AND ((NOT (`fa`.`type`=1)) OR (fa.type is NULL)) LIMIT 20
But this code, which i think is correct, and should be used since in the future i could switch database type:
$query->joinWith('fields_a fa');
$query->andFilterWhere(
['or',
['not',['fa.type' => $this->notConnectedTo]],
['fa.type'=>NULL],
]);
Executes this query:
SELECT `anag`.* FROM `anag` LEFT JOIN `fields_a` `fa` ON `anag`.`id` = `fa`.`field`
WHERE (`archived`=0) AND ((NOT (`fa`.`type`=1))) LIMIT 20
Why the => NULL where part is ignored?
In the manual says
['status' => null] generates status IS NULL.
And in other situations it seems to work.
http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail