不要怂,就是干,撸起袖子干!

Commit 811e7a6e by Simeon Theobald Committed by Jan Aagaard Meier

Add include:[{model: User.scope('...')}] section (#6357)

1 parent 71fc3f84
Showing with 11 additions and 0 deletions
......@@ -60,6 +60,17 @@ Project.scope('deleted').findAll(); // Removes the default scope
SELECT * FROM projects WHERE deleted = true
```
It is also possible to include scoped models in a scope definition. This allows you to avoid duplicating `include`, `attributes` or `where` definitions.
Using the above example, and invoking the `active` scope on the included User model (rather than specifying the condition directly in that include object):
```js
activeUsers: {
include: [
{ model: User.scope('active')}
]
}
```
# Usage
Scopes are applied by calling `.scope` on the model definition, passing the name of one or more scopes. `.scope` returns a fully functional model instance with all the regular methods: `.findAll`, `.update`, `.count`, `.destroy` etc. You can save this model instance and reuse it later:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!