forked from mirror/gorm
Merge branch 'RichardKnop-bugfix/hastable-string'
This commit is contained in:
commit
3c9d2b1af6
12
main_test.go
12
main_test.go
|
@ -165,12 +165,24 @@ func TestHasTable(t *testing.T) {
|
||||||
Stuff string
|
Stuff string
|
||||||
}
|
}
|
||||||
DB.DropTable(&Foo{})
|
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 {
|
if ok := DB.HasTable(&Foo{}); ok {
|
||||||
t.Errorf("Table should not exist, but does")
|
t.Errorf("Table should not exist, but does")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We create the table
|
||||||
if err := DB.CreateTable(&Foo{}).Error; err != nil {
|
if err := DB.CreateTable(&Foo{}).Error; err != nil {
|
||||||
t.Errorf("Table should be created")
|
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 {
|
if ok := DB.HasTable(&Foo{}); !ok {
|
||||||
t.Errorf("Table should exist, but HasTable informs it does not")
|
t.Errorf("Table should exist, but HasTable informs it does not")
|
||||||
}
|
}
|
||||||
|
|
4
scope.go
4
scope.go
|
@ -267,6 +267,10 @@ type dbTabler interface {
|
||||||
|
|
||||||
// TableName get table name
|
// TableName get table name
|
||||||
func (scope *Scope) TableName() string {
|
func (scope *Scope) TableName() string {
|
||||||
|
if strTableName, ok := scope.Value.(string); ok {
|
||||||
|
return strTableName
|
||||||
|
}
|
||||||
|
|
||||||
if scope.Search != nil && len(scope.Search.tableName) > 0 {
|
if scope.Search != nil && len(scope.Search.tableName) > 0 {
|
||||||
return scope.Search.tableName
|
return scope.Search.tableName
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue