Apply Before('gorm:row_query') for row query callbacks w/o specify order for compatibility

This commit is contained in:
Jinzhu 2017-01-16 09:48:06 +08:00
parent a3b8b332ed
commit 7fb9b62c17
1 changed files with 7 additions and 0 deletions

View File

@ -93,6 +93,13 @@ func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor {
// Register a new callback, refer `Callbacks.Create` // Register a new callback, refer `Callbacks.Create`
func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) { 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.name = callbackName
cp.processor = &callback cp.processor = &callback
cp.parent.processors = append(cp.parent.processors, cp) cp.parent.processors = append(cp.parent.processors, cp)