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

Commit cde11b7f by Jan Aagaard Meier

[ci skip] Change bulk update and destroy to use where argument

1 parent edc5cbd5
Showing with 7 additions and 10 deletions
......@@ -144,14 +144,11 @@ afterBulkCreate / afterBulkUpdate / afterBulkDestroy
If you want to emit hooks for each individual record, along with the bulk hooks you can pass `individualHooks: true` to the call.
```js
Model.destroy({accessLevel: 0}, {individualHooks: true})
Model.destroy({ where: {accessLevel: 0}}, {individualHooks: true})
// Will select all records that are about to be deleted and emit before- + after- Destroy on each instance
Model.update({username: 'Toni'}, {accessLevel: 0}, {individualHooks: true})
Model.update({username: 'Toni'}, { where: {accessLevel: 0}}, {individualHooks: true})
// Will select all records that are about to be updated and emit before- + after- Update on each instance
Model.bulkCreate({accessLevel: 0}, null, {individualHooks: true})
// Will select all records that are about to be deleted and emit before- + after- Create on each instance
```
Some model hooks have two or three parameters sent to each hook depending on it's type.
......@@ -172,13 +169,13 @@ Model.beforeBulkUpdate(function(attributes, where, fn) {
// where = second argument sent to Model.update
})
Model.update({gender: 'Male'} /*attributes argument*/, {username: 'Tom'} /*where argument*/)
Model.update({gender: 'Male'} /*attributes argument*/, { where: {username: 'Tom'}} /*where argument*/)
Model.beforeBulkDestroy(function(whereClause, fn) {
// whereClause = first argument sent to Model.destroy
})
Model.destroy({username: 'Tom'} /*whereClause argument*/)
Model.destroy({ where: {username: 'Tom'}} /*whereClause argument*/)
```
## Associations
......
......@@ -155,8 +155,8 @@ Task.bulkCreate([
{subject: 'programming', status: 'finished'}
]).success(function() {
Task.update(
{status: 'inactive'} /* set attributes' value */,
{subject: 'programming'} /* where criteria */
{ status: 'inactive' } /* set attributes' value */,
{ where: { subject: 'programming' }} /* where criteria */
).success(function(affectedRows) {
// affectedRows will be 2
Task.findAll().success(function(tasks) {
......@@ -175,7 +175,7 @@ Task.bulkCreate([
{subject: 'programming', status: 'finished'}
]).success(function() {
Task.destroy(
{subject: 'programming'} /* where criteria */,
{ where: {subject: 'programming'}} /* where criteria */,
{truncate: true /* truncate the whole table, ignoring where criteria */} /* options */
).success(function(affectedRows) {
// affectedRows will be 2
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!