Add SetTableNameHandler

This commit is contained in:
Jinzhu 2015-04-08 14:00:29 +08:00
parent b9a39be9c5
commit e2eef50fb4
2 changed files with 5 additions and 2 deletions

View File

@ -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
}

View File

@ -247,8 +247,7 @@ func (scope *Scope) TableName() string {
} }
if scope.GetModelStruct().TableName != nil { if scope.GetModelStruct().TableName != nil {
scope.Search.tableName = scope.GetModelStruct().TableName(scope.db) return scope.GetModelStruct().TableName(scope.db)
return scope.Search.tableName
} }
scope.Err(errors.New("wrong table name")) scope.Err(errors.New("wrong table name"))