Skip to content

feat: add BeforeFind hook#7370

Closed
MhmdGol wants to merge 3 commits intogo-gorm:masterfrom
MhmdGol:master
Closed

feat: add BeforeFind hook#7370
MhmdGol wants to merge 3 commits intogo-gorm:masterfrom
MhmdGol:master

Conversation

@MhmdGol
Copy link

@MhmdGol MhmdGol commented Feb 16, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Added BeforeFind hook capability to the queries. Closes #7357

User Case Description

From now on Find, First, Take and so on can have before hook.
It will be executed before executing query itself.

type Product struct {
    Code string
    Price float64
}

func (s *Product) BeforeFind() error {
    // do something before query
}

@MhmdGol
Copy link
Author

MhmdGol commented Feb 16, 2025

@a631807682 and @daheige
Can you please review?

@mrubiottec
Copy link

Looking forward to getting this added in GORM. Is there an update on this?

@jinzhu
Copy link
Member

jinzhu commented May 22, 2025

We won’t be accepting this proposal, as it could lead to some misuse.

Thank you for your PR.

@jinzhu jinzhu closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BeforeFind

3 participants