MCPcopy
hub / github.com/go-gorm/gorm / BeforeUpdate

Function BeforeUpdate

callbacks/update.go:33–53  ·  view source on GitHub ↗

BeforeUpdate before update hooks

(db *gorm.DB)

Source from the content-addressed store, hash-verified

31
32// BeforeUpdate before update hooks
33func BeforeUpdate(db *gorm.DB) {
34 if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.BeforeSave || db.Statement.Schema.BeforeUpdate) {
35 callMethod(db, func(value interface{}, tx *gorm.DB) (called bool) {
36 if db.Statement.Schema.BeforeSave {
37 if i, ok := value.(BeforeSaveInterface); ok {
38 called = true
39 db.AddError(i.BeforeSave(tx))
40 }
41 }
42
43 if db.Statement.Schema.BeforeUpdate {
44 if i, ok := value.(BeforeUpdateInterface); ok {
45 called = true
46 db.AddError(i.BeforeUpdate(tx))
47 }
48 }
49
50 return called
51 })
52 }
53}
54
55// Update update hook
56func Update(config *Config) func(db *gorm.DB) {

Callers

nothing calls this directly

Calls 4

callMethodFunction · 0.85
AddErrorMethod · 0.65
BeforeSaveMethod · 0.65
BeforeUpdateMethod · 0.65

Tested by

no test coverage detected