BeforeUpdate before update hooks
(db *gorm.DB)
| 31 | |
| 32 | // BeforeUpdate before update hooks |
| 33 | func 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 |
| 56 | func Update(config *Config) func(db *gorm.DB) { |
nothing calls this directly
no test coverage detected