From 7fb9b62c17d90320e0582a4720db025c1652fd6a Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 16 Jan 2017 09:48:06 +0800 Subject: [PATCH] Apply Before('gorm:row_query') for row query callbacks w/o specify order for compatibility --- callback.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/callback.go b/callback.go index 88dd233bf..17f754519 100644 --- a/callback.go +++ b/callback.go @@ -93,6 +93,13 @@ func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor { // Register a new callback, refer `Callbacks.Create` func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) { + if cp.kind == "row_query" { + if cp.before == "" && cp.after == "" && callbackName != "gorm:row_query" { + fmt.Printf("Registing RowQuery callback %v without specify order with Before(), After(), applying Before('gorm:row_query') by default for compatibility...\n", callbackName) + cp.before = "gorm:row_query" + } + } + cp.name = callbackName cp.processor = &callback cp.parent.processors = append(cp.parent.processors, cp)