Merge pull request #603 from leonmaia/master

fixes #593 - Dont include quotes on dest table
This commit is contained in:
Jinzhu 2015-08-10 10:43:32 +08:00
commit 8efbe276e8
1 changed files with 1 additions and 1 deletions

View File

@ -575,7 +575,7 @@ func (scope *Scope) addForeignKey(field string, dest string, onDelete string, on
var keyName = fmt.Sprintf("%s_%s_%s_foreign", table, field, regexp.MustCompile("[^a-zA-Z]").ReplaceAllString(dest, "_")) var keyName = fmt.Sprintf("%s_%s_%s_foreign", table, field, regexp.MustCompile("[^a-zA-Z]").ReplaceAllString(dest, "_"))
keyName = regexp.MustCompile("_+").ReplaceAllString(keyName, "_") keyName = regexp.MustCompile("_+").ReplaceAllString(keyName, "_")
var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;` var query = `ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s ON DELETE %s ON UPDATE %s;`
scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.QuoteIfPossible(keyName), scope.QuoteIfPossible(field), scope.QuoteIfPossible(dest), onDelete, onUpdate)).Exec() scope.Raw(fmt.Sprintf(query, scope.QuotedTableName(), scope.QuoteIfPossible(keyName), scope.QuoteIfPossible(field), dest, onDelete, onUpdate)).Exec()
} }
func (scope *Scope) removeIndex(indexName string) { func (scope *Scope) removeIndex(indexName string) {