Remove unnecessary field

This commit is contained in:
Jinzhu 2013-11-10 22:29:53 +08:00
parent f82d036f14
commit 0cb1c1ba32
5 changed files with 19 additions and 19 deletions

View File

@ -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
View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -278,7 +278,7 @@ func (m *Model) typeName() string {
return typ.Name()
}
func (m *Model) tableName(singularTableName bool) (str string, err error) {
func (m *Model) tableName() (str string, err error) {
if m.data == nil {
err = errors.New("Model haven't been set")
return