From 607ec2a70884e881f4b8d7fcfaef83f49def5910 Mon Sep 17 00:00:00 2001 From: phblj Date: Sun, 27 Oct 2024 05:38:12 -0700 Subject: [PATCH] fix: join relationship query with undeleted contacts (#7387) --- .../Web/ViewHelpers/ModuleRelationshipViewHelper.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleRelationshipViewHelper.php b/app/Domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleRelationshipViewHelper.php index 3fa255db11d..867ee8a59d1 100644 --- a/app/Domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleRelationshipViewHelper.php +++ b/app/Domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleRelationshipViewHelper.php @@ -28,10 +28,13 @@ public static function data(Contact $contact, User $user): array $relationshipTypesCollection = collect(); foreach ($relationshipTypes as $relationshipType) { $relations = DB::table('relationships') - ->join('contacts', 'relationships.contact_id', '=', 'contacts.id') + ->join('contacts as contact1', 'relationships.contact_id', '=', 'contact1.id') + ->join('contacts as contact2', 'relationships.related_contact_id', '=', 'contact2.id') ->join('relationship_types', 'relationships.relationship_type_id', '=', 'relationship_types.id') - ->select('relationships.id as main_id', 'relationship_types.id', 'relationships.contact_id', 'relationships.related_contact_id') + ->select('relationships.id as main_id', 'relationship_types.id', 'relationships.contact_id', 'relationships.related_contact_id', 'contact1.deleted_at', 'contact2.deleted_at') ->where('relationships.relationship_type_id', $relationshipType->id) + ->where('contact1.deleted_at', null) + ->where('contact2.deleted_at', null) ->where(function ($query) use ($contact) { $query->where('relationships.contact_id', $contact->id) ->orWhere('relationships.related_contact_id', $contact->id);