forked from mirror/gorm
fix when index name is "type", parseFieldIndexes will set index TYPE is "TYPE" (#5155)
* fix index name is type, parseFieldIndexes will set index TYPE is "TYPE" * check TYPE empty
This commit is contained in:
parent
f961bf1c14
commit
61b4c31236
|
@ -92,7 +92,8 @@ func parseFieldIndexes(field *Field) (indexes []Index) {
|
||||||
name string
|
name string
|
||||||
tag = strings.Join(v[1:], ":")
|
tag = strings.Join(v[1:], ":")
|
||||||
idx = strings.Index(tag, ",")
|
idx = strings.Index(tag, ",")
|
||||||
settings = ParseTagSetting(tag, ",")
|
tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
|
||||||
|
settings = ParseTagSetting(tagSetting, ",")
|
||||||
length, _ = strconv.Atoi(settings["LENGTH"])
|
length, _ = strconv.Atoi(settings["LENGTH"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ type UserIndex struct {
|
||||||
Age int64 `gorm:"index:profile,expression:ABS(age),option:WITH PARSER parser_name"`
|
Age int64 `gorm:"index:profile,expression:ABS(age),option:WITH PARSER parser_name"`
|
||||||
OID int64 `gorm:"index:idx_id;index:idx_oid,unique"`
|
OID int64 `gorm:"index:idx_id;index:idx_oid,unique"`
|
||||||
MemberNumber string `gorm:"index:idx_id,priority:1"`
|
MemberNumber string `gorm:"index:idx_id,priority:1"`
|
||||||
|
Name7 string `gorm:"index:type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseIndex(t *testing.T) {
|
func TestParseIndex(t *testing.T) {
|
||||||
|
@ -78,6 +79,11 @@ func TestParseIndex(t *testing.T) {
|
||||||
Class: "UNIQUE",
|
Class: "UNIQUE",
|
||||||
Fields: []schema.IndexOption{{Field: &schema.Field{Name: "OID"}}},
|
Fields: []schema.IndexOption{{Field: &schema.Field{Name: "OID"}}},
|
||||||
},
|
},
|
||||||
|
"type": {
|
||||||
|
Name: "type",
|
||||||
|
Type: "",
|
||||||
|
Fields: []schema.IndexOption{{Field: &schema.Field{Name: "Name7"}}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
indices := user.ParseIndexes()
|
indices := user.ParseIndexes()
|
||||||
|
|
Loading…
Reference in New Issue