Skip to content

feat: [#833] Add WithoutGlobalScopes for Orm#1335

Merged
hwbrzzl merged 2 commits intomasterfrom
bowen/#833
Jan 3, 2026
Merged

feat: [#833] Add WithoutGlobalScopes for Orm#1335
hwbrzzl merged 2 commits intomasterfrom
bowen/#833

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jan 1, 2026

📑 Description

Closes goravel/goravel#833

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested a review from a team as a code owner January 1, 2026 09:13
@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 enhances the ORM's global scope management by introducing a mechanism to selectively disable global scopes. This provides developers with greater flexibility to control query behavior, allowing them to bypass default constraints when necessary, thereby improving the adaptability of the ORM for diverse data retrieval scenarios.

Highlights

  • New Feature: WithoutGlobalScopes: Introduced a new WithoutGlobalScopes method to the ORM's Query interface, allowing specific global scopes or all global scopes to be disabled for a query.
  • Global Scope Interface Update: The ModelWithGlobalScopes interface has been updated to return a map[string]func(Query) Query instead of a slice, enabling named global scopes for more granular control.
  • Implementation and Logic: The database/gorm/query.go file now includes the implementation for WithoutGlobalScopes and modifies the addGlobalScopes method to correctly apply or bypass global scopes based on the provided names or a wildcard.
  • Comprehensive Testing: Extensive test cases have been added and updated in tests/query_test.go and tests/to_sql_test.go to cover the new WithoutGlobalScopes functionality and the changes to named global scopes across various ORM operations.
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.

@codecov
Copy link

codecov bot commented Jan 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.05%. Comparing base (e7fa6ed) to head (48cdfbf).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1335   +/-   ##
=======================================
  Coverage   70.05%   70.05%           
=======================================
  Files         281      281           
  Lines       16767    16767           
=======================================
  Hits        11746    11746           
  Misses       4530     4530           
  Partials      491      491           

☔ 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.

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 introduces the WithoutGlobalScopes feature, allowing users to disable global scopes on ORM queries. The implementation is solid, involving a change to how global scopes are defined (from a slice to a named map) and updating the query builder to handle scope exclusion. The changes are well-tested, covering both the new functionality and its impact on existing methods.

My review includes a few suggestions to improve robustness and test reliability:

  • Preventing duplicate entries when disabling scopes multiple times.
  • Refactoring duplicated test setup code for better maintainability.
  • Adding OrderBy clauses to several tests to prevent flakiness by ensuring a deterministic order of results.

Overall, this is a great addition to the framework. The change from an anonymous slice of scopes to a named map is a significant but necessary improvement for this feature.


var globalScopes []func(contractsorm.Query) contractsorm.Query

names := slices.Sorted(maps.Keys(nameToGlobalScopes))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort it to avoid test failure.

@hwbrzzl hwbrzzl merged commit 090a31f into master Jan 3, 2026
13 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#833 branch January 3, 2026 01:16
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.

Add WithoutGlobalScopes for Orm

1 participant