diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index 61cd94b1..2b722619 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -178,7 +178,7 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]string) } for _, names := range sqlIndexes { - name := strings.Join(names, "_") + name := mi.table + "_" + strings.Join(names, "_") cols := strings.Join(names, sep) sql := fmt.Sprintf("CREATE INDEX %s%s%s ON %s%s%s (%s%s%s);", Q, name, Q, Q, mi.table, Q, Q, cols, Q) tableIndexes[mi.table] = append(tableIndexes[mi.table], sql) diff --git a/orm/models_test.go b/orm/models_test.go index 2367e5f0..fe7c3e2d 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -81,6 +81,7 @@ type User struct { func (u *User) TableIndex() [][]string { return [][]string{ []string{"Id", "UserName"}, + []string{"Id", "Created"}, } } @@ -121,6 +122,12 @@ type Post struct { Tags []*Tag `orm:"rel(m2m)"` } +func (u *Post) TableIndex() [][]string { + return [][]string{ + []string{"Id", "Created"}, + } +} + func NewPost() *Post { obj := new(Post) return obj