Merge aa7b10be2907bb37995bf74fae0fd79a1236a3aa into 0a51f6cdc55d1650d9ed3b4c13026cfa9133b01e

This commit is contained in:
abdesselemaymen 2017-10-20 09:37:21 +00:00 committed by GitHub
commit d433743787
3 changed files with 9 additions and 7 deletions

View File

@ -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")

View File

@ -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")
}

View File

@ -266,6 +266,7 @@ 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() {
if indirect(fieldValue).IsValid() {
result := fieldValue.Interface()
if r, ok := result.(driver.Valuer); ok {
result, _ = r.Value()
@ -274,6 +275,7 @@ func getValueFromFields(value reflect.Value, fieldNames []string) (results []int
}
}
}
}
return
}