Oprava počtu řádků při GROUP BY přes více sloupců (Nette Database Table) - #1294
Open
radimvaculik wants to merge 2 commits into
Open
Oprava počtu řádků při GROUP BY přes více sloupců (Nette Database Table)#1294radimvaculik wants to merge 2 commits into
radimvaculik wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1294 +/- ##
==========================================
+ Coverage 49.12% 49.29% +0.16%
==========================================
Files 63 64 +1
Lines 2974 2978 +4
==========================================
+ Hits 1461 1468 +7
+ Misses 1513 1510 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
getCount() nahrazuje neplatné COUNT(DISTINCT sloupec1, sloupec2, ...) počítáním skupin přes poddotaz, takže vrací správný počet i když seskupovací sloupce obsahují NULL hodnoty. Řeší issue #991.
Metoda Selection::getExplorer() existuje až v nette/database 3.2.9, ale CI běží s 3.2.8. Použití zavedeného reflection helperu getContext() funguje napříč podporovanými verzemi.
radimvaculik
force-pushed
the
fix/issue-991-grouped-count
branch
from
August 1, 2026 12:52
c92fc68 to
e7e14b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NetteDatabaseTableDataSource::getCount()generated invalid SQL for selections grouped by multiple columns. When aGROUP BYwas present it builtCOUNT(DISTINCT col1, col2, ...), which:NULL, so the count is undercounted (returns0when every row has aNULLin one of the grouping columns).wrong number of arguments to function COUNT().Fixes #991.
Fix
Count the number of groups via a subquery instead of relying on
COUNT(DISTINCT ...):This matches the approach already used by
NetteDatabaseDataSource::getCount()and returns the correct count regardless ofNULLvalues in the grouping columns. The duplicatedGROUP BYhandling in both branches of the method was consolidated into a single early check.Tests
Added
testGetCountWithGroupByMultipleColumns()reproducing the issue scenario (grouping by four columns withNULLvalues, 4 rows → 3 groups).getCount()now returns3, consistent withgetData().make qa(PHPStan + phpcs) and the full test suite pass.