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 9e78d786
authored
Dec 04, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): provide .field support for .update
1 parent
c42f6b7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
lib/model.js
test/model/attributes.test.js
lib/model.js
View file @
9e78d78
...
...
@@ -1640,6 +1640,15 @@ module.exports = (function() {
return
[
results
.
length
,
results
];
}
Object
.
keys
(
valuesUse
).
forEach
(
function
(
attr
)
{
if
(
self
.
rawAttributes
[
attr
].
field
&&
self
.
rawAttributes
[
attr
].
field
!==
attr
)
{
valuesUse
[
self
.
rawAttributes
[
attr
].
field
]
=
valuesUse
[
attr
];
delete
valuesUse
[
attr
];
}
});
mapFieldNames
.
call
(
self
,
options
,
self
);
// Run query to update all rows
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(),
valuesUse
,
options
.
where
,
options
,
self
.
tableAttributes
).
then
(
function
(
affectedRows
)
{
if
(
options
.
returning
)
{
...
...
test/model/attributes.test.js
View file @
9e78d78
...
...
@@ -222,6 +222,30 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
});
it
(
'should bulk update'
,
function
()
{
var
Entity
=
this
.
sequelize
.
define
(
'Entity'
,
{
strField
:
{
type
:
Sequelize
.
STRING
,
field
:
'str_field'
},
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Entity
.
create
({
strField
:
'foo'
});
}).
then
(
function
()
{
return
Entity
.
update
(
{
strField
:
'bar'
},
{
where
:
{
strField
:
'foo'
}}
);
}).
then
(
function
()
{
return
Entity
.
findOne
({
where
:
{
strField
:
'bar'
}
}).
then
(
function
(
entity
)
{
expect
(
entity
).
to
.
be
.
ok
;
expect
(
entity
.
get
(
'strField'
)).
to
.
equal
(
'bar'
);
});
});
});
it
(
'should not contain the field properties after create'
,
function
()
{
var
Model
=
this
.
sequelize
.
define
(
'test'
,
{
id
:
{
...
...
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