feat: add force method for namer
This commit is contained in:
parent
328f301982
commit
5720f7d515
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user