6686d923 by slene

orm fix create index

1 parent 7c72b2dc
...@@ -178,7 +178,7 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]string) ...@@ -178,7 +178,7 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]string)
178 } 178 }
179 179
180 for _, names := range sqlIndexes { 180 for _, names := range sqlIndexes {
181 name := strings.Join(names, "_") 181 name := mi.table + "_" + strings.Join(names, "_")
182 cols := strings.Join(names, sep) 182 cols := strings.Join(names, sep)
183 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) 183 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)
184 tableIndexes[mi.table] = append(tableIndexes[mi.table], sql) 184 tableIndexes[mi.table] = append(tableIndexes[mi.table], sql)
......
...@@ -81,6 +81,7 @@ type User struct { ...@@ -81,6 +81,7 @@ type User struct {
81 func (u *User) TableIndex() [][]string { 81 func (u *User) TableIndex() [][]string {
82 return [][]string{ 82 return [][]string{
83 []string{"Id", "UserName"}, 83 []string{"Id", "UserName"},
84 []string{"Id", "Created"},
84 } 85 }
85 } 86 }
86 87
...@@ -121,6 +122,12 @@ type Post struct { ...@@ -121,6 +122,12 @@ type Post struct {
121 Tags []*Tag `orm:"rel(m2m)"` 122 Tags []*Tag `orm:"rel(m2m)"`
122 } 123 }
123 124
125 func (u *Post) TableIndex() [][]string {
126 return [][]string{
127 []string{"Id", "Created"},
128 }
129 }
130
124 func NewPost() *Post { 131 func NewPost() *Post {
125 obj := new(Post) 132 obj := new(Post)
126 return obj 133 return obj
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!