after Update nil point panic
This commit is contained in:
parent
201bf96f8e
commit
f07e779830
@ -107,9 +107,9 @@ func Update(config *Config) func(db *gorm.DB) {
|
||||
|
||||
// AfterUpdate after update hooks
|
||||
func AfterUpdate(db *gorm.DB) {
|
||||
if !db.Statement.ReflectValue.CanAddr() {
|
||||
return
|
||||
}
|
||||
//if !db.Statement.ReflectValue.CanAddr() {
|
||||
// return
|
||||
//}
|
||||
|
||||
if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.AfterSave || db.Statement.Schema.AfterUpdate) {
|
||||
callMethod(db, func(value interface{}, tx *gorm.DB) (called bool) {
|
||||
|
@ -255,7 +255,7 @@ func TestUseDBInHooks(t *testing.T) {
|
||||
}
|
||||
|
||||
testPanic := Product2{Name: "testPanic", Price: 100}
|
||||
DB.Create(testPanic)
|
||||
DB.Create(&testPanic)
|
||||
DB.Model(Product2{}).Where("name", "testPanic").Update("name", "testPanic1")
|
||||
|
||||
var result Product2
|
||||
|
Loading…
x
Reference in New Issue
Block a user