Check argument is string or not in HasTable

This commit is contained in:
Jinzhu 2016-02-14 14:17:14 +08:00
parent 3c9d2b1af6
commit 77928d8373
2 changed files with 11 additions and 6 deletions

13
main.go
View File

@ -406,8 +406,17 @@ func (s *DB) DropTableIfExists(values ...interface{}) *DB {
}
func (s *DB) HasTable(value interface{}) bool {
scope := s.clone().NewScope(value)
tableName := scope.TableName()
var (
scope = s.clone().NewScope(value)
tableName string
)
if name, ok := value.(string); ok {
tableName = name
} else {
tableName = scope.TableName()
}
has := scope.Dialect().HasTable(scope, tableName)
s.AddError(scope.db.Error)
return has

View File

@ -267,10 +267,6 @@ type dbTabler interface {
// TableName get table name
func (scope *Scope) TableName() string {
if strTableName, ok := scope.Value.(string); ok {
return strTableName
}
if scope.Search != nil && len(scope.Search.tableName) > 0 {
return scope.Search.tableName
}