From dd606225ceb8e99146166ea62bf2fcfeb13ce5b6 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 2 Apr 2020 12:47:23 +0530 Subject: [PATCH] dev/core#1685 - Search builder returns DB error on Group => Empty condition --- CRM/Contact/BAO/Query.php | 4 ++-- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 2124cbf460..c4a7354cf3 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2990,8 +2990,8 @@ class CRM_Contact_BAO_Query { // even one group might equate to multiple when looking at children so IN is simpler. // @todo - also look at != casting but there are rows below to review. $opReplacements = [ - 'EMPTY' => 'NULL', - 'NOT EMPTY' => 'NOT NULL', + 'IS EMPTY' => 'IS NULL', + 'IS NOT EMPTY' => 'IS NOT NULL', '=' => 'IN', ]; if (isset($opReplacements[$op])) { diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 00b2c6c708..7ccffd8c9e 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -862,6 +862,10 @@ civicrm_relationship.is_active = 1 AND $queryObj = new CRM_Contact_BAO_Query([['group', '=', $groupID, 0, 0], ['group_contact_status', 'IN', ['Removed' => 1], 0, 0]]); $resultDAO = $queryObj->searchQuery(); $this->assertEquals(1, $resultDAO->N); + + $queryObj = new CRM_Contact_BAO_Query([['group', 'IS NOT EMPTY', '', 0, 0], ['group_contact_status', 'IN', ['Removed' => 1], 0, 0]]); + $resultDAO = $queryObj->searchQuery(); + $this->assertEquals(1, $resultDAO->N); } /** -- 2.25.1