forked from mirror/gorm
Lazy call registered scopes
This commit is contained in:
parent
940da051a7
commit
828e6b646b
12
callbacks.go
12
callbacks.go
|
@ -72,8 +72,10 @@ func (cs *callbacks) Raw() *processor {
|
|||
}
|
||||
|
||||
func (p *processor) Execute(db *DB) {
|
||||
curTime := time.Now()
|
||||
stmt := db.Statement
|
||||
var (
|
||||
curTime = time.Now()
|
||||
stmt = db.Statement
|
||||
)
|
||||
|
||||
if stmt.Model == nil {
|
||||
stmt.Model = stmt.Dest
|
||||
|
@ -106,6 +108,12 @@ func (p *processor) Execute(db *DB) {
|
|||
}
|
||||
}
|
||||
|
||||
// call scopes
|
||||
for _, scope := range stmt.scopes {
|
||||
db = scope(db)
|
||||
}
|
||||
stmt.scopes = nil
|
||||
|
||||
for _, f := range p.fns {
|
||||
f(db)
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ type Statement struct {
|
|||
CurDestIndex int
|
||||
attrs []interface{}
|
||||
assigns []interface{}
|
||||
scopes []func(*DB) *DB
|
||||
}
|
||||
|
||||
type join struct {
|
||||
|
@ -481,6 +482,10 @@ func (stmt *Statement) clone() *Statement {
|
|||
copy(newStmt.Joins, stmt.Joins)
|
||||
}
|
||||
|
||||
for _, scope := range stmt.scopes {
|
||||
stmt.scopes = append(stmt.scopes, scope)
|
||||
}
|
||||
|
||||
stmt.Settings.Range(func(k, v interface{}) bool {
|
||||
newStmt.Settings.Store(k, v)
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue