diff --git a/schema/naming.go b/schema/naming.go index a258beed..aedd6455 100644 --- a/schema/naming.go +++ b/schema/naming.go @@ -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 diff --git a/schema/schema.go b/schema/schema.go index 42ff5c45..8a1c4628 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -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