From e2eef50fb4bd50c8cb899f73d317723a22a1fdfc Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 8 Apr 2015 14:00:29 +0800 Subject: [PATCH] Add SetTableNameHandler --- main.go | 4 ++++ scope.go | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7049675e..86301207 100644 --- a/main.go +++ b/main.go @@ -487,3 +487,7 @@ func (s *DB) SetJoinTableHandler(source interface{}, column string, handler Join } } } + +func (s *DB) SetTableNameHandler(source interface{}, handler func(*DB) string) { + s.NewScope(source).GetModelStruct().TableName = handler +} diff --git a/scope.go b/scope.go index 86994a85..b83581e2 100644 --- a/scope.go +++ b/scope.go @@ -247,8 +247,7 @@ func (scope *Scope) TableName() string { } if scope.GetModelStruct().TableName != nil { - scope.Search.tableName = scope.GetModelStruct().TableName(scope.db) - return scope.Search.tableName + return scope.GetModelStruct().TableName(scope.db) } scope.Err(errors.New("wrong table name"))