forked from mirror/gorm
Add SetTableNameHandler
This commit is contained in:
parent
b9a39be9c5
commit
e2eef50fb4
4
main.go
4
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
|
||||
}
|
||||
|
|
3
scope.go
3
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"))
|
||||
|
|
Loading…
Reference in New Issue