Respect Where when create index

This commit is contained in:
Jinzhu 2015-10-01 06:53:15 +08:00
parent 58596afda1
commit 88188b6161
2 changed files with 4 additions and 2 deletions

View File

@ -816,7 +816,7 @@ func TestNilPointerSlice(t *testing.T) {
}
var got []Level1
if err := DB.Debug().Preload("Level2").Preload("Level2.Level3").Find(&got).Error; err != nil {
if err := DB.Preload("Level2").Preload("Level2.Level3").Find(&got).Error; err != nil {
panic(err)
}

View File

@ -579,7 +579,9 @@ func (scope *Scope) addIndex(unique bool, indexName string, column ...string) {
sqlCreate = "CREATE UNIQUE INDEX"
}
scope.Raw(fmt.Sprintf("%s %v ON %v(%v);", sqlCreate, indexName, scope.QuotedTableName(), strings.Join(columns, ", "))).Exec()
scope.Search.Unscoped = true
scope.Raw(fmt.Sprintf("%s %v ON %v(%v) %v", sqlCreate, indexName, scope.QuotedTableName(), strings.Join(columns, ", "), scope.whereSql())).Exec()
scope.Search.Unscoped = false
}
func (scope *Scope) addForeignKey(field string, dest string, onDelete string, onUpdate string) {