Skip to content

Commit

Permalink
Fix customers search on PostgreSQL - closes #1664
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jan 24, 2022
1 parent 813bc84 commit c10686e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,8 @@ public function searchCustomers($request, $user)
// Like is case insensitive.
$like = '%'.mb_strtolower($q).'%';

$query_customers = Customer::select(['customers.*', 'emails.email'])
// We need to use aggregate function for email to avoid "Grouping error" error in PostgreSQL.
$query_customers = Customer::select(['customers.*', \DB::raw('MAX(emails.email)')])
->groupby('customers.id')
->leftJoin('emails', function ($join) {
$join->on('customers.id', '=', 'emails.customer_id');
Expand Down

0 comments on commit c10686e

Please sign in to comment.