forked from mirror/gorm
Check argument is string or not in HasTable
This commit is contained in:
parent
3c9d2b1af6
commit
77928d8373
13
main.go
13
main.go
|
@ -406,8 +406,17 @@ func (s *DB) DropTableIfExists(values ...interface{}) *DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) HasTable(value interface{}) bool {
|
func (s *DB) HasTable(value interface{}) bool {
|
||||||
scope := s.clone().NewScope(value)
|
var (
|
||||||
tableName := scope.TableName()
|
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)
|
has := scope.Dialect().HasTable(scope, tableName)
|
||||||
s.AddError(scope.db.Error)
|
s.AddError(scope.db.Error)
|
||||||
return has
|
return has
|
||||||
|
|
4
scope.go
4
scope.go
|
@ -267,10 +267,6 @@ 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