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 bfdda598
authored
Dec 16, 2015
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix(#4520): Cloned values passed to Model.update
1 parent
332017b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
0 deletions
changelog.md
lib/model.js
test/unit/model/update.test.js
changelog.md
View file @
bfdda59
# Future
-
[
FIXED
]
calling Model.update() modifies passed values
[
#4520
](
https://github.com/sequelize/sequelize/issues/4520
)
# 3.15.0
-
[
ADDED
]
Improve support for pg range type to handle unbound ranges, +/-infinity bounds and empty ranges
-
[
FIXED
]
Postgres issue when using named timezone
[
#4307
](
https://github.com/sequelize/sequelize/issues/4307
)
...
...
lib/model.js
View file @
bfdda59
...
...
@@ -2403,6 +2403,9 @@ Model.prototype.update = function(values, options) {
Model
.
$injectScope
(
this
.
$scope
,
options
);
// Clone values so it doesn't get modified for caller scope
values
=
_
.
clone
(
values
);
// Remove values that are not in the options.fields
if
(
options
.
fields
&&
options
.
fields
instanceof
Array
)
{
Object
.
keys
(
values
).
forEach
(
function
(
key
)
{
...
...
test/unit/model/update.test.js
0 → 100644
View file @
bfdda59
'use strict'
;
/* jshint -W030 */
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
)
,
Promise
=
current
.
Promise
,
DataTypes
=
require
(
'../../../lib/data-types'
)
,
_
=
require
(
'lodash'
);
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
function
()
{
describe
(
'method update'
,
function
()
{
var
User
=
current
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
INTEGER
});
before
(
function
()
{
this
.
stubUpdate
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkUpdate'
,
function
()
{
return
Promise
.
resolve
([]);
});
});
beforeEach
(
function
()
{
this
.
updates
=
{
name
:
'Batman'
,
secretValue
:
'7'
};
this
.
cloneUpdates
=
_
.
clone
(
this
.
updates
);
this
.
stubUpdate
.
reset
();
});
afterEach
(
function
()
{
delete
this
.
updates
;
delete
this
.
cloneUpdates
;
});
after
(
function
()
{
this
.
stubUpdate
.
restore
();
});
describe
(
'properly clones input values'
,
function
()
{
it
(
'with default options'
,
function
()
{
var
self
=
this
;
return
User
.
update
(
self
.
updates
,
{
where
:
{
secretValue
:
'1'
}}).
bind
(
this
).
then
(
function
(
e
)
{
expect
(
self
.
updates
).
to
.
be
.
deep
.
eql
(
self
.
cloneUpdates
);
});
});
it
(
'when using fields option'
,
function
()
{
var
self
=
this
;
return
User
.
update
(
self
.
updates
,
{
where
:
{
secretValue
:
'1'
},
fields
:
[
'name'
]}).
bind
(
this
).
then
(
function
()
{
expect
(
self
.
updates
).
to
.
be
.
deep
.
eql
(
self
.
cloneUpdates
);
});
});
});
});
});
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