Skip to content

fix: [#856] Distinct will no effect when using with Count#1345

Merged
hwbrzzl merged 1 commit intomasterfrom
bowen/#856-1
Jan 10, 2026
Merged

fix: [#856] Distinct will no effect when using with Count#1345
hwbrzzl merged 1 commit intomasterfrom
bowen/#856-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jan 10, 2026

📑 Description

Closes goravel/goravel#856

Follow Gemini

✅ Checks

  • Added test cases for my code

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hwbrzzl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the database query builder where the Distinct clause was not correctly applied when performing Count operations. The changes introduce a more robust mechanism for generating COUNT SQL queries, ensuring that DISTINCT is properly honored when specified with columns. This significantly improves the accuracy of aggregate functions and enhances the overall reliability and flexibility of the query builder, particularly in scenarios involving unique record counts and pagination.

Highlights

  • Fix Distinct with Count: Resolved an issue where the Distinct clause had no effect when used in conjunction with Count operations, ensuring correct SQL generation for distinct counts.
  • Enhanced Count Logic: Introduced a new helper function buildSelectForCount to intelligently construct COUNT queries, handling various Select and Distinct scenarios, including column renaming and multiple selected columns.
  • Error Handling for Distinct Count: Added specific error handling for Distinct().Count() calls that do not specify any columns, preventing unexpected behavior and guiding developers.
  • Comprehensive Test Coverage: Expanded test suites across query_test.go, db_test.go, and to_sql_test.go to validate the new Count and Distinct logic under various conditions, including Paginate operations.
  • Version Update: The framework version has been updated from v1.16.5 to v1.17.0.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@hwbrzzl hwbrzzl marked this pull request as ready for review January 10, 2026 13:36
@hwbrzzl hwbrzzl requested a review from a team as a code owner January 10, 2026 13:36
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue where Distinct() had no effect when used with Count(). The introduction of the buildSelectForCount helper function in both the db and gorm packages provides a clean solution to handle various scenarios, including column aliases. The added tests are comprehensive and cover many edge cases, which significantly improves the robustness of the query builder. I have a couple of minor suggestions to improve the readability and robustness of the new helper functions.

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.27%. Comparing base (42a167d) to head (734e4ed).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1345   +/-   ##
=======================================
  Coverage   70.27%   70.27%           
=======================================
  Files         281      281           
  Lines       17121    17121           
=======================================
  Hits        12031    12031           
  Misses       4579     4579           
  Partials      511      511           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl hwbrzzl merged commit 23dba56 into master Jan 10, 2026
13 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#856-1 branch January 10, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distinct will no effect when using with Count

1 participant