Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enforce hooks on every query? #7325

Open
wawhal opened this issue Dec 22, 2024 · 0 comments
Open

How to enforce hooks on every query? #7325

wawhal opened this issue Dec 22, 2024 · 0 comments
Assignees
Labels
type:question general questions

Comments

@wawhal
Copy link

wawhal commented Dec 22, 2024

Your Question

I have a BaseModel that has a GetDefaultFilters method. All my models implement BaseModel. GetDefaultFilters returns some default filters that must be injected in the where clause of every query on that model. How do I enforce this through hooks?

I used the before query hook, and it worked beautifully but that gets executed only for a few functions like Find, First etc. When I use Scan, it gets skipped.

If this is not possible, is there a way to only allow Find on these models?

The document you expected this should be explained

https://gorm.io/docs/hooks.html

Expected answer

@wawhal wawhal added the type:question general questions label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants