diff --git a/callback_update.go b/callback_update.go index 6948439f..6404e334 100644 --- a/callback_update.go +++ b/callback_update.go @@ -41,7 +41,7 @@ func beforeUpdateCallback(scope *Scope) { scope.CallMethod("BeforeSave") } if !scope.HasError() { - scope.CallMethod("BeforeUpdate") + scope.CallMethod("GormBeforeUpdate") } } } @@ -100,7 +100,7 @@ func updateCallback(scope *Scope) { func afterUpdateCallback(scope *Scope) { if _, ok := scope.Get("gorm:update_column"); !ok { if !scope.HasError() { - scope.CallMethod("AfterUpdate") + scope.CallMethod("GormAfterUpdate") } if !scope.HasError() { scope.CallMethod("AfterSave") diff --git a/callbacks_test.go b/callbacks_test.go index a58913d7..296b7fb9 100644 --- a/callbacks_test.go +++ b/callbacks_test.go @@ -17,7 +17,7 @@ func (s *Product) BeforeCreate() (err error) { return } -func (s *Product) BeforeUpdate() (err error) { +func (s *Product) GormBeforeUpdate() (err error) { if s.Code == "dont_update" { err = errors.New("can't update") } diff --git a/utils.go b/utils.go index 97a3d175..091a3de2 100644 --- a/utils.go +++ b/utils.go @@ -266,11 +266,13 @@ func getValueFromFields(value reflect.Value, fieldNames []string) (results []int if indirectValue := reflect.Indirect(value); indirectValue.IsValid() { for _, fieldName := range fieldNames { if fieldValue := indirectValue.FieldByName(fieldName); fieldValue.IsValid() { - result := fieldValue.Interface() - if r, ok := result.(driver.Valuer); ok { - result, _ = r.Value() + if indirect(fieldValue).IsValid() { + result := fieldValue.Interface() + if r, ok := result.(driver.Valuer); ok { + result, _ = r.Value() + } + results = append(results, result) } - results = append(results, result) } } }