API4: "!=" has unexpected results on NULL fields
Overview
Using the !=
operator when some of the values are NULL
does not return the NULL
records.
Reproduction steps
- On a demo site (which by default has no contacts with a subtype), search for contacts that are not of subtype "Parent". E.g.:
\Civi\Api4\Contact::get(TRUE)
->addWhere('contact_sub_type', '!=', 'Parent')
->execute();
Current behaviour
No results are returned.
Expected behaviour
All results are returned, since no record is a Parent.
Comments
I thought at some point, !=
internally generated != and IS NOT NULL
but maybe that was somewhere else.
I just learned about the MySQL null-safe equals operator, which would also solve this problem: https://stackoverflow.com/a/44723097/2832108