From 5d4aae2d116f7031dd1819ec83424a5e236bc9b5 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 15 Feb 2016 16:23:26 +0800 Subject: [PATCH] Don't sort processors that without name --- callback.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/callback.go b/callback.go index 309078e4..3335f1db 100644 --- a/callback.go +++ b/callback.go @@ -128,9 +128,9 @@ func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *S // Get registered callback // db.Callback().Create().Get("gorm:create") func (cp *CallbackProcessor) Get(callbackName string) (callback func(scope *Scope)) { - for _, processor := range cp.parent.processors { - if processor.name == callbackName && processor.kind == cp.kind && !cp.remove { - return *cp.processor + for _, p := range cp.parent.processors { + if p.name == callbackName && p.kind == cp.kind && !cp.remove { + return *p.processor } } return nil @@ -215,17 +215,19 @@ func (c *Callback) reorder() { var creates, updates, deletes, queries, rowQueries []*CallbackProcessor for _, processor := range c.processors { - switch processor.kind { - case "create": - creates = append(creates, processor) - case "update": - updates = append(updates, processor) - case "delete": - deletes = append(deletes, processor) - case "query": - queries = append(queries, processor) - case "row_query": - rowQueries = append(rowQueries, processor) + if processor.name != "" { + switch processor.kind { + case "create": + creates = append(creates, processor) + case "update": + updates = append(updates, processor) + case "delete": + deletes = append(deletes, processor) + case "query": + queries = append(queries, processor) + case "row_query": + rowQueries = append(rowQueries, processor) + } } }