mirror of https://github.com/go-gorm/gorm.git
Remove uncessary method CallMethodWithErrorCheck for Scope
This commit is contained in:
parent
de73d30503
commit
31366f388f
|
@ -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() {
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
scope.go
8
scope.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue