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
|
// AfterUpdate after update hooks
|
||||||
func AfterUpdate(db *gorm.DB) {
|
func AfterUpdate(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.AfterSave || db.Statement.Schema.AfterUpdate) {
|
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) {
|
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}
|
testPanic := Product2{Name: "testPanic", Price: 100}
|
||||||
DB.Create(testPanic)
|
DB.Create(&testPanic)
|
||||||
DB.Model(Product2{}).Where("name", "testPanic").Update("name", "testPanic1")
|
DB.Model(Product2{}).Where("name", "testPanic").Update("name", "testPanic1")
|
||||||
|
|
||||||
var result Product2
|
var result Product2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user