contributte / contributte/datagrid
Incorrect rows count when using GROUP BY with multiple columns - Nette\Database\Table
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 296
- Forks
- 215
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I found the bug in Nette\Database\Table data source when using GROUP BY with multiple columns.
Here is example of SQL queries.
Query for the datagrid with 703 total rows.
SELECT `id`, `title`, `variant`, CONCAT_WS(" - ", `title`, `variant`, `course_city`, `course_date`) AS `full_name`
FROM `orders_products`
GROUP BY `title`, `variant`, `course_city`, `course_date`;
Datagrid generated this SQL query from the getCount() function which gets 0 rows.
SELECT COUNT(DISTINCT `title`, `variant`, `course_city`, `course_date`)
FROM `orders_products`;
I think right SQL query with multiple GROUP BY columns should be:
SELECT COUNT(*)
FROM (
SELECT COUNT(id)
FROM `orders_products`
GROUP BY `title`, `variant`, `course_city`, `course_date`
) AS x;
Best regards
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 at Nette\Database\Table's getCount() behavior and reproduce the reported datagrid query with GROUP BY on title, variant, course_city, and course_date. Compare the generated COUNT(DISTINCT ...) result with the grouped query's 703 rows; done means the count is correct for multiple GROUP BY columns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100