forked from mirror/gorm
Remove unnecessary field
This commit is contained in:
parent
f82d036f14
commit
0cb1c1ba32
2
chain.go
2
chain.go
|
@ -12,7 +12,6 @@ type Chain struct {
|
|||
db *sql.DB
|
||||
driver string
|
||||
debug bool
|
||||
singularTableName bool
|
||||
value interface{}
|
||||
|
||||
Errors []error
|
||||
|
@ -69,7 +68,6 @@ func (s *Chain) do(value interface{}) *Do {
|
|||
do.limitStr = s.limitStr
|
||||
do.specifiedTableName = s.specifiedTableName
|
||||
do.unscoped = s.unscoped
|
||||
do.singularTableName = s.singularTableName
|
||||
do.debug = s.debug
|
||||
|
||||
s.value = value
|
||||
|
|
3
do.go
3
do.go
|
@ -37,13 +37,12 @@ type Do struct {
|
|||
unscoped bool
|
||||
updateAttrs map[string]interface{}
|
||||
ignoreProtectedAttrs bool
|
||||
singularTableName bool
|
||||
}
|
||||
|
||||
func (s *Do) tableName() string {
|
||||
if s.specifiedTableName == "" {
|
||||
var err error
|
||||
s.guessedTableName, err = s.model.tableName(s.singularTableName)
|
||||
s.guessedTableName, err = s.model.tableName()
|
||||
s.err(err)
|
||||
return s.guessedTableName
|
||||
} else {
|
||||
|
|
10
gorm_test.go
10
gorm_test.go
|
@ -1218,27 +1218,29 @@ func TestTableName(t *testing.T) {
|
|||
var table string
|
||||
|
||||
model := &Model{data: Order{}}
|
||||
table, _ = model.tableName(false)
|
||||
table, _ = model.tableName()
|
||||
if table != "orders" {
|
||||
t.Errorf("Order table name should be orders")
|
||||
}
|
||||
|
||||
table, _ = model.tableName(true)
|
||||
db.SingularTable(true)
|
||||
table, _ = model.tableName()
|
||||
if table != "order" {
|
||||
t.Errorf("Order's singular table name should be order")
|
||||
}
|
||||
|
||||
model2 := &Model{data: Cart{}}
|
||||
table, _ = model2.tableName(false)
|
||||
table, _ = model2.tableName()
|
||||
if table != "shopping_cart" {
|
||||
t.Errorf("Cart's singular table name should be shopping_cart")
|
||||
}
|
||||
|
||||
model3 := &Model{data: &Cart{}}
|
||||
table, _ = model3.tableName(false)
|
||||
table, _ = model3.tableName()
|
||||
if table != "shopping_cart" {
|
||||
t.Errorf("Cart's singular table name should be shopping_cart")
|
||||
}
|
||||
db.SingularTable(false)
|
||||
}
|
||||
|
||||
type BigEmail struct {
|
||||
|
|
7
main.go
7
main.go
|
@ -2,11 +2,12 @@ package gorm
|
|||
|
||||
import "database/sql"
|
||||
|
||||
var singularTableName bool
|
||||
|
||||
type DB struct {
|
||||
db *sql.DB
|
||||
driver string
|
||||
DebugMode bool
|
||||
SingularTableName bool
|
||||
}
|
||||
|
||||
func Open(driver, source string) (db DB, err error) {
|
||||
|
@ -20,11 +21,11 @@ func (s *DB) SetPool(n int) {
|
|||
}
|
||||
|
||||
func (s *DB) SingularTable(result bool) {
|
||||
s.SingularTableName = result
|
||||
singularTableName = result
|
||||
}
|
||||
|
||||
func (s *DB) buildChain() *Chain {
|
||||
return &Chain{db: s.db, driver: s.driver, debug: s.DebugMode, singularTableName: s.SingularTableName}
|
||||
return &Chain{db: s.db, driver: s.driver, debug: s.DebugMode}
|
||||
}
|
||||
|
||||
func (s *DB) Where(querystring interface{}, args ...interface{}) *Chain {
|
||||
|
|
Loading…
Reference in New Issue