CRM-20740 - Fix issue with check for custom_nn => ['IS NULL' => 1].
authorJohan Vervloet <johan.vervloet@kuleuven.be>
Thu, 15 Jun 2017 19:51:04 +0000 (21:51 +0200)
committerJohan Vervloet <johan.vervloet@kuleuven.be>
Thu, 15 Jun 2017 19:51:04 +0000 (21:51 +0200)
Civi/API/Api3SelectQuery.php

index 1585b152b12d88e2ea28771a293180c1a5e2c1d7..bb3f458ebc04b1d1d2b1f5ae1bcf018c01e79097 100644 (file)
@@ -89,7 +89,10 @@ class Api3SelectQuery extends SelectQuery {
         $column_name = $key;
       }
       elseif (($cf_id = \CRM_Core_BAO_CustomField::getKeyID($key)) != FALSE) {
-        list($table_name, $column_name) = $this->addCustomField($this->apiFieldSpec['custom_' . $cf_id], 'INNER');
+        // If we check a custom field on 'IS NULL', it should also work when there is no
+        // record in the custom value table, see CRM-20740.
+        $side = empty($value['IS NULL']) ? 'INNER': 'LEFT OUTER';
+        list($table_name, $column_name) = $this->addCustomField($this->apiFieldSpec['custom_' . $cf_id], $side);
       }
       elseif (strpos($key, '.')) {
         $fkInfo = $this->addFkField($key, 'INNER');