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"))