From 77928d8373099c01b7dfdf8a2bc33bcbfe813616 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 14 Feb 2016 14:17:14 +0800 Subject: [PATCH] Check argument is string or not in HasTable --- main.go | 13 +++++++++++-- scope.go | 4 ---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index ff707f3f..f2eeb5d6 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/scope.go b/scope.go index 2fa4acdb..a11d4ec4 100644 --- a/scope.go +++ b/scope.go @@ -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 }