Skip to content

Commit 16d99c7

Browse files
committed
add distinct select to fix Postgres error
1 parent 6a10052 commit 16d99c7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Cmgmyr/Messenger/Models/Thread.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ public function scopeForUserWithNewMessages($query, $userId)
174174
*/
175175
public function scopeBetween($query, array $participants)
176176
{
177-
$query->whereHas('participants', function ($query) use ($participants) {
178-
$query->whereIn('user_id', $participants)
177+
return $query->whereHas('participants', function ($q) use ($participants) {
178+
$q->whereIn('user_id', $participants)
179+
->select($this->getConnection()->raw('DISTINCT(thread_id)'))
179180
->groupBy('thread_id')
180181
->havingRaw('COUNT(thread_id)=' . count($participants));
181182
});

0 commit comments

Comments
 (0)