Skip to content

Commit

Permalink
Allow table option when DropTable, close go-gorm#1514
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Feb 12, 2018
1 parent 30adc80 commit 8005321
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ func (scope *Scope) getTableOptions() string {
if !ok {
return ""
}
return tableOptions.(string)
return " " + tableOptions.(string)
}

func (scope *Scope) createJoinTable(field *StructField) {
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func (scope *Scope) createJoinTable(field *StructField) {
}
}

scope.Err(scope.NewDB().Exec(fmt.Sprintf("CREATE TABLE %v (%v, PRIMARY KEY (%v)) %s", scope.Quote(joinTable), strings.Join(sqlTypes, ","), strings.Join(primaryKeys, ","), scope.getTableOptions())).Error)
scope.Err(scope.NewDB().Exec(fmt.Sprintf("CREATE TABLE %v (%v, PRIMARY KEY (%v))%s", scope.Quote(joinTable), strings.Join(sqlTypes, ","), strings.Join(primaryKeys, ","), scope.getTableOptions())).Error)
}
scope.NewDB().Table(joinTable).AutoMigrate(joinTableHandler)
}
Expand Down Expand Up @@ -1147,14 +1147,14 @@ func (scope *Scope) createTable() *Scope {
primaryKeyStr = fmt.Sprintf(", PRIMARY KEY (%v)", strings.Join(primaryKeys, ","))
}

scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v %v) %s", scope.QuotedTableName(), strings.Join(tags, ","), primaryKeyStr, scope.getTableOptions())).Exec()
scope.Raw(fmt.Sprintf("CREATE TABLE %v (%v %v)%s", scope.QuotedTableName(), strings.Join(tags, ","), primaryKeyStr, scope.getTableOptions())).Exec()

scope.autoIndex()
return scope
}

func (scope *Scope) dropTable() *Scope {
scope.Raw(fmt.Sprintf("DROP TABLE %v", scope.QuotedTableName())).Exec()
scope.Raw(fmt.Sprintf("DROP TABLE %v%s", scope.QuotedTableName(), scope.getTableOptions())).Exec()
return scope
}

Expand Down

0 comments on commit 8005321

Please sign in to comment.