forked from mirror/gorm
HasTable now works with table name passed as a string.
Before, only HasTable(&Foo) would work but HasTable("foos") would always return false. This PR fixes that.
This commit is contained in:
parent
0cf369dcff
commit
f73f7b251f
12
main_test.go
12
main_test.go
|
@ -165,12 +165,24 @@ func TestHasTable(t *testing.T) {
|
|||
Stuff string
|
||||
}
|
||||
DB.DropTable(&Foo{})
|
||||
|
||||
// Table should not exist at this point, HasTable should return false
|
||||
if ok := DB.HasTable("foos"); ok {
|
||||
t.Errorf("Table should not exist, but does")
|
||||
}
|
||||
if ok := DB.HasTable(&Foo{}); ok {
|
||||
t.Errorf("Table should not exist, but does")
|
||||
}
|
||||
|
||||
// We create the table
|
||||
if err := DB.CreateTable(&Foo{}).Error; err != nil {
|
||||
t.Errorf("Table should be created")
|
||||
}
|
||||
|
||||
// And now it should exits, and HasTable should return true
|
||||
if ok := DB.HasTable("foos"); !ok {
|
||||
t.Errorf("Table should exist, but HasTable informs it does not")
|
||||
}
|
||||
if ok := DB.HasTable(&Foo{}); !ok {
|
||||
t.Errorf("Table should exist, but HasTable informs it does not")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue