Lazy call registered scopes

This commit is contained in:
Jinzhu 2021-02-25 20:06:26 +08:00
parent 828e6b646b
commit 6b7d18656d
1 changed files with 4 additions and 5 deletions

View File

@ -240,11 +240,10 @@ func (db *DB) Offset(offset int) (tx *DB) {
// }
//
// db.Scopes(AmountGreaterThan1000, OrderStatus([]string{"paid", "shipped"})).Find(&orders)
func (db *DB) Scopes(funcs ...func(*DB) *DB) *DB {
for _, f := range funcs {
db = f(db)
}
return db
func (db *DB) Scopes(funcs ...func(*DB) *DB) (tx *DB) {
tx = db.getInstance()
tx.Statement.scopes = append(tx.Statement.scopes, funcs...)
return tx
}
// Preload preload associations with given conditions