Skip to content

Commit

Permalink
fix: join relationship query with undeleted contacts (#7387)
Browse files Browse the repository at this point in the history
  • Loading branch information
phblj authored Oct 27, 2024
1 parent 3e875d3 commit 607ec2a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 607ec2a

Please sign in to comment.