Remove uncessary method CallMethodWithErrorCheck for Scope

This commit is contained in:
Jinzhu 2016-01-17 16:14:14 +08:00
parent de73d30503
commit 31366f388f
5 changed files with 35 additions and 17 deletions

View File

@ -6,8 +6,12 @@ import (
) )
func beforeCreateCallback(scope *Scope) { func beforeCreateCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("BeforeSave") if !scope.HasError() {
scope.CallMethodWithErrorCheck("BeforeCreate") scope.CallMethod("BeforeSave")
}
if !scope.HasError() {
scope.CallMethod("BeforeCreate")
}
} }
func updateTimeStampForCreateCallback(scope *Scope) { func updateTimeStampForCreateCallback(scope *Scope) {
@ -109,8 +113,12 @@ func forceReloadAfterCreateCallback(scope *Scope) {
} }
func afterCreateCallback(scope *Scope) { func afterCreateCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("AfterCreate") if !scope.HasError() {
scope.CallMethodWithErrorCheck("AfterSave") scope.CallMethod("AfterCreate")
}
if !scope.HasError() {
scope.CallMethod("AfterSave")
}
} }
func init() { func init() {

View File

@ -3,7 +3,9 @@ package gorm
import "fmt" import "fmt"
func beforeDeleteCallback(scope *Scope) { func beforeDeleteCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("BeforeDelete") if !scope.HasError() {
scope.CallMethod("BeforeDelete")
}
} }
func deleteCallback(scope *Scope) { func deleteCallback(scope *Scope) {
@ -24,7 +26,9 @@ func deleteCallback(scope *Scope) {
} }
func afterDeleteCallback(scope *Scope) { func afterDeleteCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("AfterDelete") if !scope.HasError() {
scope.CallMethod("AfterDelete")
}
} }
func init() { func init() {

View File

@ -79,7 +79,9 @@ func queryCallback(scope *Scope) {
} }
func afterQueryCallback(scope *Scope) { func afterQueryCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("AfterFind") if !scope.HasError() {
scope.CallMethod("AfterFind")
}
} }
func init() { func init() {

View File

@ -26,8 +26,12 @@ func assignUpdateAttributesCallback(scope *Scope) {
func beforeUpdateCallback(scope *Scope) { func beforeUpdateCallback(scope *Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok { if _, ok := scope.Get("gorm:update_column"); !ok {
scope.CallMethodWithErrorCheck("BeforeSave") if !scope.HasError() {
scope.CallMethodWithErrorCheck("BeforeUpdate") scope.CallMethod("BeforeSave")
}
if !scope.HasError() {
scope.CallMethod("BeforeUpdate")
}
} }
} }
@ -77,8 +81,12 @@ func updateCallback(scope *Scope) {
func afterUpdateCallback(scope *Scope) { func afterUpdateCallback(scope *Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok { if _, ok := scope.Get("gorm:update_column"); !ok {
scope.CallMethodWithErrorCheck("AfterUpdate") if !scope.HasError() {
scope.CallMethodWithErrorCheck("AfterSave") scope.CallMethod("AfterUpdate")
}
if !scope.HasError() {
scope.CallMethod("AfterSave")
}
} }
} }

View File

@ -192,8 +192,8 @@ func (scope *Scope) SetColumn(column interface{}, value interface{}) error {
return errors.New("could not convert column to field") return errors.New("could not convert column to field")
} }
func (scope *Scope) CallMethod(name string, checkError bool) { func (scope *Scope) CallMethod(name string) {
if scope.Value == nil || (checkError && scope.HasError()) { if scope.Value == nil {
return return
} }
@ -239,10 +239,6 @@ func (scope *Scope) CallMethod(name string, checkError bool) {
} }
} }
func (scope *Scope) CallMethodWithErrorCheck(name string) {
scope.CallMethod(name, true)
}
// AddToVars add value as sql's vars, gorm will escape them // AddToVars add value as sql's vars, gorm will escape them
func (scope *Scope) AddToVars(value interface{}) string { func (scope *Scope) AddToVars(value interface{}) string {
if expr, ok := value.(*expr); ok { if expr, ok := value.(*expr); ok {