Fix distinct count in SelectModifierListener#22
Merged
Conversation
…in `SelectModifierListener`
There was a problem hiding this comment.
Pull request overview
This PR refactors how “counting” list queries are built by centralizing the count/group-by behavior in SelectModifierListener and removing the dedicated GroupByModifierListener. The goal is to make count queries consistently use a distinct count of the main record ID and avoid grouping during counts.
Changes:
- Simplifies counting select generation to always use
COUNT(DISTINCT(main.id))inSelectModifierListener. - Ensures counting queries explicitly clear
GROUP BYviaSelectModifierListener. - Removes the now-redundant
GroupByModifierListener.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/EventListener/QueryStructModifier/SelectModifierListener.php |
Centralizes counting-query select and group-by clearing logic; updates PHPDoc/exception import. |
src/EventListener/QueryStructModifier/GroupByModifierListener.php |
Removes the separate listener that previously nulled GROUP BY for count queries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request primarily refactors the way counting queries are handled in the query struct modifiers. The most important changes involve removing the now-unnecessary
GroupByModifierListenerand simplifying the logic for counting queries in theSelectModifierListener. This results in cleaner and more maintainable code.Refactoring and Simplification of Counting Query Logic:
GroupByModifierListenerclass entirely, consolidating its logic into theSelectModifierListener. This reduces redundancy and centralizes counting query modifications.SelectModifierListener, the counting query now always usesCOUNT(DISTINCT(main.id))(instead of switching betweenCOUNT(*)andCOUNT(DISTINCT ...)depending on joins), and explicitly setsgroupBytonullfor counting queries.Exception Handling and Documentation:
SelectModifierListener::__invokefrom a customAbortFilteringExceptionto the more generalDoctrine\DBAL\Exception, and updated the docblock to reflect this. [1] [2]