MedicOneSystems / MedicOneSystems/livewire-datatables
NumberColumn::raw using filter ( filterable() ) gives error when use the operation SUM() with GroupBy() (want to use WHERE instead HAVING)
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how NumberColumn::raw() and filterable() build conditions for the shown grouped Petition query. Reproduce the SUM(cant) filter with groupBy('person_id') and compare the generated WHERE and HAVING clauses. Done means aggregate filters use HAVING while non-aggregate filters remain in WHERE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php, sql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100