mardi 25 juin 2019

How to fix error "sql_mode=only_full_group_by " when use 'group by' in has() eloquent relationship?

I need to get the data that group by the "delivery_date", I use has() relationship but It's error about "sql_mode=only_full_group_by"

I tested this code below.

$customers = Customer::has('deliveries')->with(['deliveries' => function($q) {
       $q->get();
}])->get();

It's return the all data (customer relationship with delivery table) normally.

But when I tried this code, It's error SELECT list is not in GROUP BY clause and contains nonaggregated column 'express_dry_cleaning.deliveries.customer_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.

 $customers = Customer::has('deliveries')
            ->with(['deliveries' => function($q) {
                $q->selectRaw('count(id) as delivery_count, customer_id')
                    ->groupBy('delivery_date')
                    ->count();
            }])->get();

I expect the output of count delivery id, group by delivery date.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2X2mdz1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire