forked from mirror/gorm
Fix nested Scopes, close #4196
This commit is contained in:
parent
a3d9bbfc36
commit
e85b73e5a5
|
@ -109,11 +109,13 @@ func (p *processor) Execute(db *DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// call scopes
|
// call scopes
|
||||||
|
for len(stmt.scopes) > 0 {
|
||||||
scopes := stmt.scopes
|
scopes := stmt.scopes
|
||||||
stmt.scopes = nil
|
stmt.scopes = nil
|
||||||
for _, scope := range scopes {
|
for _, scope := range scopes {
|
||||||
db = scope(db)
|
db = scope(db)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, f := range p.fns {
|
for _, f := range p.fns {
|
||||||
f(db)
|
f(db)
|
||||||
|
|
|
@ -8,11 +8,13 @@ import (
|
||||||
// Migrator returns migrator
|
// Migrator returns migrator
|
||||||
func (db *DB) Migrator() Migrator {
|
func (db *DB) Migrator() Migrator {
|
||||||
// apply scopes to migrator
|
// apply scopes to migrator
|
||||||
|
for len(db.Statement.scopes) > 0 {
|
||||||
scopes := db.Statement.scopes
|
scopes := db.Statement.scopes
|
||||||
db.Statement.scopes = nil
|
db.Statement.scopes = nil
|
||||||
for _, scope := range scopes {
|
for _, scope := range scopes {
|
||||||
db = scope(db)
|
db = scope(db)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return db.Dialector.Migrator(db.Session(&Session{}))
|
return db.Dialector.Migrator(db.Session(&Session{}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue