diff --git a/schema/naming.go b/schema/naming.go index 9b7c9471..ecdab791 100644 --- a/schema/naming.go +++ b/schema/naming.go @@ -41,6 +41,10 @@ func (ns NamingStrategy) ColumnName(table, column string) string { // JoinTableName convert string to join table name func (ns NamingStrategy) JoinTableName(str string) string { + if strings.ToLower(str) == str { + return str + } + if ns.SingularTable { return ns.TablePrefix + toDBName(str) } diff --git a/schema/relationship_test.go b/schema/relationship_test.go index f2d63323..b9279b9f 100644 --- a/schema/relationship_test.go +++ b/schema/relationship_test.go @@ -206,16 +206,16 @@ func TestMany2ManyOverrideJoinForeignKey(t *testing.T) { type User struct { gorm.Model - Profiles []Profile `gorm:"many2many:user_profiles;JoinForeignKey:UserReferID;JoinReferences:ProfileRefer"` + Profiles []Profile `gorm:"many2many:user_profile;JoinForeignKey:UserReferID;JoinReferences:ProfileRefer"` Refer uint } checkStructRelation(t, &User{}, Relation{ Name: "Profiles", Type: schema.Many2Many, Schema: "User", FieldSchema: "Profile", - JoinTable: JoinTable{Name: "user_profiles", Table: "user_profiles"}, + JoinTable: JoinTable{Name: "user_profile", Table: "user_profile"}, References: []Reference{ - {"ID", "User", "UserReferID", "user_profiles", "", true}, - {"ID", "Profile", "ProfileRefer", "user_profiles", "", false}, + {"ID", "User", "UserReferID", "user_profile", "", true}, + {"ID", "Profile", "ProfileRefer", "user_profile", "", false}, }, }) }