mirror of https://github.com/go-gorm/gorm.git
Change unique_idnex to UniqueIndex
This commit is contained in:
parent
f93345afa8
commit
2416eabd3f
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
@ -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)"`
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue