Skip to content

Commit

Permalink
add distinct select to fix Postgres error
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Nov 11, 2016
1 parent e8992e5 commit 459a6aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Cmgmyr/Messenger/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down

0 comments on commit 459a6aa

Please sign in to comment.