Allow customize table name when creating index, close #1656

This commit is contained in:
Jinzhu 2018-02-12 11:56:45 +08:00
parent 49934ff3bf
commit 7e2bb3d7fa
1 changed files with 2 additions and 2 deletions

View File

@ -1250,13 +1250,13 @@ func (scope *Scope) autoIndex() *Scope {
}
for name, columns := range indexes {
if db := scope.NewDB().Model(scope.Value).AddIndex(name, columns...); db.Error != nil {
if db := scope.NewDB().Table(scope.TableName()).Model(scope.Value).AddIndex(name, columns...); db.Error != nil {
scope.db.AddError(db.Error)
}
}
for name, columns := range uniqueIndexes {
if db := scope.NewDB().Model(scope.Value).AddUniqueIndex(name, columns...); db.Error != nil {
if db := scope.NewDB().Table(scope.TableName()).Model(scope.Value).AddUniqueIndex(name, columns...); db.Error != nil {
scope.db.AddError(db.Error)
}
}