Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit cde11b7f
authored
Nov 28, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ci skip] Change bulk update and destroy to use where argument
1 parent
edc5cbd5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
docs/docs/hooks.md
docs/docs/instances.md
docs/docs/hooks.md
View file @
cde11b7
...
...
@@ -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
...
...
docs/docs/instances.md
View file @
cde11b7
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment