From 6ce3ea658be9537092127ae9ce9f7f7736d81c9e Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Fri, 30 Oct 2020 11:08:42 +0100 Subject: [PATCH] Fix for dev/core#2152 --- CRM/Contact/BAO/Relationship.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 7fe41c1b75e9..85a8f53822f1 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1896,14 +1896,15 @@ public static function getPermissionedContacts($contactID, $relTypeId = NULL, $n public static function mergeRelationships($mainId, $otherId, &$sqls) { // Delete circular relationships $sqls[] = "DELETE FROM civicrm_relationship - WHERE (contact_id_a = $mainId AND contact_id_b = $otherId) - OR (contact_id_b = $mainId AND contact_id_a = $otherId)"; + WHERE (contact_id_a = $mainId AND contact_id_b = $otherId AND case_id IS NULL) + OR (contact_id_b = $mainId AND contact_id_a = $otherId AND case_id IS NULL)"; // Delete relationship from other contact if main contact already has that relationship $sqls[] = "DELETE r2 FROM civicrm_relationship r1, civicrm_relationship r2 WHERE r1.relationship_type_id = r2.relationship_type_id AND r1.id <> r2.id + AND r1.case_id IS NULL AND r2.case_id IS NULL AND ( r1.contact_id_a = $mainId AND r2.contact_id_a = $otherId AND r1.contact_id_b = r2.contact_id_b OR r1.contact_id_b = $mainId AND r2.contact_id_b = $otherId AND r1.contact_id_a = r2.contact_id_a