From 459a6aac70349be010f4fb3656185c60796ae8ea Mon Sep 17 00:00:00 2001 From: Chris Gmyr Date: Fri, 11 Nov 2016 17:02:44 -0500 Subject: [PATCH] add distinct select to fix Postgres error --- src/Cmgmyr/Messenger/Models/Thread.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Cmgmyr/Messenger/Models/Thread.php b/src/Cmgmyr/Messenger/Models/Thread.php index 73a6bda..6f18d96 100644 --- a/src/Cmgmyr/Messenger/Models/Thread.php +++ b/src/Cmgmyr/Messenger/Models/Thread.php @@ -174,8 +174,9 @@ public function scopeForUserWithNewMessages($query, $userId) */ public function scopeBetween($query, array $participants) { - $query->whereHas('participants', function ($query) use ($participants) { - $query->whereIn('user_id', $participants) + return $query->whereHas('participants', function ($q) use ($participants) { + $q->whereIn('user_id', $participants) + ->select($this->getConnection()->raw('DISTINCT(thread_id)')) ->groupBy('thread_id') ->havingRaw('COUNT(thread_id)=' . count($participants)); });