add nocascade method

This commit is contained in:
Lunny Xiao 2013-12-19 22:32:00 +08:00
parent 59412a951c
commit 31dbc146ee
2 changed files with 28 additions and 8 deletions

View File

@ -19,6 +19,7 @@ const (
SQLITE = "sqlite3"
MYSQL = "mysql"
MYMYSQL = "mymysql"
ORACLE_OCI = "oci8"
)
// a dialect is a driver's wrapper
@ -140,6 +141,12 @@ func (engine *Engine) NoCache() *Session {
return session.NoCache()
}
func (engine *Engine) NoCascade() *Session {
session := engine.NewSession()
session.IsAutoClose = true
return session.NoCascade()
}
// Set a table use a special cacher
func (engine *Engine) MapCacher(bean interface{}, cacher Cacher) {
t := rType(bean)

View File

@ -129,6 +129,16 @@ func (session *Session) Cols(columns ...string) *Session {
return session
}
func (session *Session) NoCascade() *Session {
session.Statement.UseCascade = false
return session
}
/*
func (session *Session) MustCols(columns ...string) *Session {
session.Statement.Must()
}*/
// Xorm automatically retrieve condition according struct, but
// if struct has bool field, it will ignore them. So use UseBool
// to tell system to do not ignore them.
@ -635,11 +645,14 @@ func (session *Session) cacheGet(bean interface{}, sql string, args ...interface
newSession := session.Engine.NewSession()
defer newSession.Close()
cacheBean = reflect.New(structValue.Type()).Interface()
newSession.Id(id).NoCache()
if session.Statement.AltTableName != "" {
has, err = newSession.Id(id).NoCache().Table(session.Statement.AltTableName).Get(cacheBean)
} else {
has, err = newSession.Id(id).NoCache().Get(cacheBean)
newSession.Table(session.Statement.AltTableName)
}
if !session.Statement.UseCascade {
newSession.NoCascade()
}
has, err = newSession.Get(cacheBean)
if err != nil || !has {
return has, err
}
@ -2129,7 +2142,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
}
// --
colNames, args, err := table.genCols(session, bean, false, false)
colNames, args, err := table.genCols(session, bean, true, false)
if err != nil {
return 0, err
}