mirror of https://github.com/go-gorm/gorm.git
Fix DropTableIfExists with string
This commit is contained in:
parent
39e6f58111
commit
e541ca5cdf
4
main.go
4
main.go
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue