Skip to content

Commit

Permalink
Merge pull request #179 from cmgmyr/bug/#174-postgres-between-fix, fixes
Browse files Browse the repository at this point in the history
 #174

add distinct select to fix Postgres error
  • Loading branch information
cmgmyr authored Nov 17, 2016
2 parents e8992e5 + 459a6aa commit 9eb9f3b
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 9eb9f3b

Please sign in to comment.