before Update nil point panic

This commit is contained in:
leiyuqing 2022-04-03 12:13:32 +08:00
parent f07e779830
commit c90013c901

View File

@ -31,9 +31,9 @@ func SetupUpdateReflectValue(db *gorm.DB) {
// BeforeUpdate before update hooks // BeforeUpdate before update hooks
func BeforeUpdate(db *gorm.DB) { func BeforeUpdate(db *gorm.DB) {
if !db.Statement.ReflectValue.CanAddr() { //if !db.Statement.ReflectValue.CanAddr() {
return // return
} //}
if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.BeforeSave || db.Statement.Schema.BeforeUpdate) { if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.BeforeSave || db.Statement.Schema.BeforeUpdate) {
callMethod(db, func(value interface{}, tx *gorm.DB) (called bool) { callMethod(db, func(value interface{}, tx *gorm.DB) (called bool) {