feat: add force method for namer

This commit is contained in:
qqxhb 2022-09-28 21:03:58 +08:00
parent 328f301982
commit 5720f7d515
2 changed files with 10 additions and 0 deletions

View File

@ -19,6 +19,7 @@ type Namer interface {
RelationshipFKName(Relationship) string
CheckerName(table, column string) string
IndexName(table, column string) string
Force() bool
}
// Replacer replacer interface like strings.Replacer
@ -32,6 +33,12 @@ type NamingStrategy struct {
SingularTable bool
NameReplacer Replacer
NoLowerCase bool
Forced bool
}
// Force be forced to use the strategy
func (ns NamingStrategy) Force() bool {
return ns.Forced
}
// TableName convert string to table name

View File

@ -124,6 +124,9 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam
tableName := namer.TableName(modelType.Name())
if tabler, ok := modelValue.Interface().(Tabler); ok {
tableName = tabler.TableName()
if namer.Force() {
tableName = namer.TableName(tableName)
}
}
if en, ok := namer.(embeddedNamer); ok {
tableName = en.Table