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) {
scope.CallMethodWithErrorCheck("BeforeSave")
scope.CallMethodWithErrorCheck("BeforeCreate")
if !scope.HasError() {
scope.CallMethod("BeforeSave")
}
if !scope.HasError() {
scope.CallMethod("BeforeCreate")
}
}
func updateTimeStampForCreateCallback(scope *Scope) {
@ -109,8 +113,12 @@ func forceReloadAfterCreateCallback(scope *Scope) {
}
func afterCreateCallback(scope *Scope) {
scope.CallMethodWithErrorCheck("AfterCreate")
scope.CallMethodWithErrorCheck("AfterSave")
if !scope.HasError() {
scope.CallMethod("AfterCreate")
}
if !scope.HasError() {
scope.CallMethod("AfterSave")
}
}
func init() {

View File

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

View File

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

View File

@ -26,8 +26,12 @@ func assignUpdateAttributesCallback(scope *Scope) {
func beforeUpdateCallback(scope *Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
scope.CallMethodWithErrorCheck("BeforeSave")
scope.CallMethodWithErrorCheck("BeforeUpdate")
if !scope.HasError() {
scope.CallMethod("BeforeSave")
}
if !scope.HasError() {
scope.CallMethod("BeforeUpdate")
}
}
}
@ -77,8 +81,12 @@ func updateCallback(scope *Scope) {
func afterUpdateCallback(scope *Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
scope.CallMethodWithErrorCheck("AfterUpdate")
scope.CallMethodWithErrorCheck("AfterSave")
if !scope.HasError() {
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")
}
func (scope *Scope) CallMethod(name string, checkError bool) {
if scope.Value == nil || (checkError && scope.HasError()) {
func (scope *Scope) CallMethod(name string) {
if scope.Value == nil {
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
func (scope *Scope) AddToVars(value interface{}) string {
if expr, ok := value.(*expr); ok {