From 7e2bb3d7fa0916f4cdf50236af59e735f7e67739 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 12 Feb 2018 11:56:45 +0800 Subject: [PATCH] Allow customize table name when creating index, close #1656 --- scope.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scope.go b/scope.go index 5ac147e4..1bd32a28 100644 --- a/scope.go +++ b/scope.go @@ -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) } }