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
|
RelationshipFKName(Relationship) string
|
||||||
CheckerName(table, column string) string
|
CheckerName(table, column string) string
|
||||||
IndexName(table, column string) string
|
IndexName(table, column string) string
|
||||||
|
Force() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replacer replacer interface like strings.Replacer
|
// Replacer replacer interface like strings.Replacer
|
||||||
@ -32,6 +33,12 @@ type NamingStrategy struct {
|
|||||||
SingularTable bool
|
SingularTable bool
|
||||||
NameReplacer Replacer
|
NameReplacer Replacer
|
||||||
NoLowerCase bool
|
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
|
// TableName convert string to table name
|
||||||
|
@ -124,6 +124,9 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam
|
|||||||
tableName := namer.TableName(modelType.Name())
|
tableName := namer.TableName(modelType.Name())
|
||||||
if tabler, ok := modelValue.Interface().(Tabler); ok {
|
if tabler, ok := modelValue.Interface().(Tabler); ok {
|
||||||
tableName = tabler.TableName()
|
tableName = tabler.TableName()
|
||||||
|
if namer.Force() {
|
||||||
|
tableName = namer.TableName(tableName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if en, ok := namer.(embeddedNamer); ok {
|
if en, ok := namer.(embeddedNamer); ok {
|
||||||
tableName = en.Table
|
tableName = en.Table
|
||||||
|
Loading…
x
Reference in New Issue
Block a user