MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

NumberColumn::raw using filter ( filterable() ) gives error when use the operation SUM() with GroupBy() (want to use WHERE instead HAVING) #467

Open insulae opened 2 years ago

insulae commented 2 years ago

The Query():

        return Petition::query()
            ->groupBy('person_id')
            ->where('type_id','2');

I have a column like this:

            NumberColumn::raw('SUM(cant) AS cant_total')
                ->filterable()
                ->enableSummary()
                ->label('Total Cant.'),

If I try to use the filter I have the error:

SQLSTATE[HY000]: General error: 1111 Invalid use of group function

 where
      (
        `type_id` = 2
      )
      and (SUM(cant) >= 1000)

this fails since the raw column is working in conjunction with the GroupBy() of my Query() so the condition should not go in WHERE, it should go with HAVING.

I dont know if I can fix this with something (I am going to try) but it will be great if livewire-datatables will apply this automatically.