Fix DropTableIfExists with string

This commit is contained in:
Jinzhu 2015-12-16 21:00:56 +08:00
parent 39e6f58111
commit e541ca5cdf
2 changed files with 7 additions and 3 deletions

View File

@ -392,6 +392,10 @@ func (s *DB) DropTable(values ...interface{}) *DB {
func (s *DB) DropTableIfExists(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if tableName, ok := value.(string); ok {
db = db.Table(tableName)
}
db = db.NewScope(value).dropTableIfExists().db
}
return db

View File

@ -632,7 +632,7 @@ func TestManyToManyPreloadWithMultiPrimaryKeys(t *testing.T) {
DB.DropTableIfExists(&Level2{})
DB.DropTableIfExists(&Level1{})
DB.Table("levels").DropTableIfExists("levels")
DB.DropTableIfExists("levels")
if err := DB.AutoMigrate(&Level2{}, &Level1{}).Error; err != nil {
panic(err)
@ -717,7 +717,7 @@ func TestManyToManyPreloadForPointer(t *testing.T) {
DB.DropTableIfExists(&Level2{})
DB.DropTableIfExists(&Level1{})
DB.Table("levels").DropTableIfExists("levels")
DB.DropTableIfExists("levels")
if err := DB.AutoMigrate(&Level2{}, &Level1{}).Error; err != nil {
panic(err)
@ -808,7 +808,7 @@ func TestManyToManyPreloadForNestedPointer(t *testing.T) {
DB.DropTableIfExists(&Level3{})
DB.DropTableIfExists(&Level2{})
DB.DropTableIfExists(&Level1{})
DB.Table("levels").DropTableIfExists("levels")
DB.DropTableIfExists("levels")
if err := DB.AutoMigrate(&Level3{}, &Level2{}, &Level1{}).Error; err != nil {
panic(err)