Issue 53 (2)
authorJaap Jansma <jaap.jansma@civicoop.org>
Thu, 8 Apr 2021 11:20:40 +0000 (13:20 +0200)
committerJaap Jansma <jaap.jansma@civicoop.org>
Thu, 8 Apr 2021 11:20:40 +0000 (13:20 +0200)
CRM/Contact/BAO/Query.php

index f581fe2558ac006596947c459f9fc279ddc694a7..76686c7848d3ca4b5c3945731e32b86437ba3cd8 100644 (file)
@@ -5792,7 +5792,7 @@ INNER JOIN civicrm_relationship displayRelType ON ( displayRelType.contact_id_a
 INNER JOIN $tableName transform_temp ON ( transform_temp.contact_id = displayRelType.contact_id_a OR transform_temp.contact_id = displayRelType.contact_id_b )
 ";
         $qcache['where'] = "
-WHERE displayRelType.relationship_type_id = {$this->_displayRelationshipType}
+AND displayRelType.relationship_type_id = {$this->_displayRelationshipType}
 AND   displayRelType.is_active = 1
 ";
       }
@@ -5813,7 +5813,7 @@ INNER JOIN $tableName transform_temp ON ( transform_temp.contact_id = displayRel
 ";
         }
         $qcache['where'] = "
-WHERE displayRelType.relationship_type_id = $relType
+AND displayRelType.relationship_type_id = $relType
 AND   displayRelType.is_active = 1
 ";
       }
@@ -5837,10 +5837,11 @@ AND   displayRelType.is_active = 1
       else {
         $from .= $qcache['from'];
       }
-      $where = $qcache['where'];
+      $where .= $qcache['where'];
       if (!empty($this->_tables['civicrm_case'])) {
         // Change the join on CiviCRM case so that it joins on the right contac from the relationship.
         $from = str_replace("ON civicrm_case_contact.contact_id = contact_a.id", "ON civicrm_case_contact.contact_id = transform_temp.contact_id", $from);
+        $where = str_replace("AND civicrm_case_contact.contact_id = contact_a.id", "AND civicrm_case_contact.contact_id = transform_temp.contact_id", $where);
         $where .= " AND displayRelType.case_id = civicrm_case_contact.case_id ";
       }
       if (!empty($this->_permissionFromClause) && !stripos($from, 'aclContactCache')) {