diff --git a/schema/index.go b/schema/index.go index cf3338c3..a0a71d2c 100644 --- a/schema/index.go +++ b/schema/index.go @@ -27,7 +27,7 @@ func (schema *Schema) ParseIndexes() map[string]Index { var indexes = map[string]Index{} for _, field := range schema.Fields { - if field.TagSettings["INDEX"] != "" || field.TagSettings["UNIQUE_INDEX"] != "" { + if field.TagSettings["INDEX"] != "" || field.TagSettings["UNIQUEINDEX"] != "" { for _, index := range parseFieldIndexes(field) { idx := indexes[index.Name] idx.Name = index.Name @@ -76,7 +76,7 @@ func parseFieldIndexes(field *Field) (indexes []Index) { if value != "" { v := strings.Split(value, ":") k := strings.TrimSpace(strings.ToUpper(v[0])) - if k == "INDEX" || k == "UNIQUE_INDEX" { + if k == "INDEX" || k == "UNIQUEINDEX" { var ( name string tag = strings.Join(v[1:], ":") @@ -97,7 +97,7 @@ func parseFieldIndexes(field *Field) (indexes []Index) { name = field.Schema.namer.IndexName(field.Schema.Table, field.Name) } - if (k == "UNIQUE_INDEX") || settings["UNIQUE"] != "" { + if (k == "UNIQUEINDEX") || settings["UNIQUE"] != "" { settings["CLASS"] = "UNIQUE" } diff --git a/schema/index_test.go b/schema/index_test.go index 71a70a8c..f6c3d247 100644 --- a/schema/index_test.go +++ b/schema/index_test.go @@ -12,7 +12,7 @@ type UserIndex struct { Name string `gorm:"index"` Name2 string `gorm:"index:idx_name,unique"` Name3 string `gorm:"index:,sort:desc,collate:utf8,type:btree,length:10,where:name3 != 'jinzhu'"` - Name4 string `gorm:"unique_index"` + Name4 string `gorm:"uniqueIndex"` Name5 int64 `gorm:"index:,class:FULLTEXT,comment:hello \\, world,where:age > 10"` Name6 int64 `gorm:"index:profile,comment:hello \\, world,where:age > 10"` Age int64 `gorm:"index:profile,expression:ABS(age)"` diff --git a/tests/associations_test.go b/tests/associations_test.go index 9b4dd105..c1a4e2b2 100644 --- a/tests/associations_test.go +++ b/tests/associations_test.go @@ -41,7 +41,7 @@ func TestForeignKeyConstraints(t *testing.T) { type Member struct { ID uint - Refer uint `gorm:"unique_index"` + Refer uint `gorm:"uniqueIndex"` Name string Profile Profile `gorm:"Constraint:OnUpdate:CASCADE,OnDelete:CASCADE;FOREIGNKEY:MemberID;References:Refer"` } @@ -91,7 +91,7 @@ func TestForeignKeyConstraintsBelongsTo(t *testing.T) { type Profile struct { ID uint Name string - Refer uint `gorm:"unique_index"` + Refer uint `gorm:"uniqueIndex"` } type Member struct {