Don't sort processors that without name

This commit is contained in:
Jinzhu 2016-02-15 16:23:26 +08:00
parent 4e8370e18b
commit 5d4aae2d11
1 changed files with 16 additions and 14 deletions

View File

@ -128,9 +128,9 @@ func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *S
// Get registered callback // Get registered callback
// db.Callback().Create().Get("gorm:create") // db.Callback().Create().Get("gorm:create")
func (cp *CallbackProcessor) Get(callbackName string) (callback func(scope *Scope)) { func (cp *CallbackProcessor) Get(callbackName string) (callback func(scope *Scope)) {
for _, processor := range cp.parent.processors { for _, p := range cp.parent.processors {
if processor.name == callbackName && processor.kind == cp.kind && !cp.remove { if p.name == callbackName && p.kind == cp.kind && !cp.remove {
return *cp.processor return *p.processor
} }
} }
return nil return nil
@ -215,6 +215,7 @@ func (c *Callback) reorder() {
var creates, updates, deletes, queries, rowQueries []*CallbackProcessor var creates, updates, deletes, queries, rowQueries []*CallbackProcessor
for _, processor := range c.processors { for _, processor := range c.processors {
if processor.name != "" {
switch processor.kind { switch processor.kind {
case "create": case "create":
creates = append(creates, processor) creates = append(creates, processor)
@ -228,6 +229,7 @@ func (c *Callback) reorder() {
rowQueries = append(rowQueries, processor) rowQueries = append(rowQueries, processor)
} }
} }
}
c.creates = sortProcessors(creates) c.creates = sortProcessors(creates)
c.updates = sortProcessors(updates) c.updates = sortProcessors(updates)