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 429e8e06
authored
Dec 22, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(instance): update should not set attributes not defined by fields, fixes #1320
1 parent
24a8ac33
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
lib/instance.js
test/instance/update.test.js
lib/instance.js
View file @
429e8e0
...
@@ -707,7 +707,7 @@ module.exports = (function() {
...
@@ -707,7 +707,7 @@ module.exports = (function() {
* @alias updateAttributes
* @alias updateAttributes
*/
*/
Instance
.
prototype
.
update
=
function
(
values
,
options
)
{
Instance
.
prototype
.
update
=
function
(
values
,
options
)
{
return
this
.
set
(
values
,
{
attributes
:
options
&&
options
.
attribute
s
}).
save
(
options
);
return
this
.
set
(
values
,
{
attributes
:
options
&&
options
.
field
s
}).
save
(
options
);
};
};
Instance
.
prototype
.
updateAttributes
=
Instance
.
prototype
.
update
;
Instance
.
prototype
.
updateAttributes
=
Instance
.
prototype
.
update
;
...
...
test/instance/update.test.js
View file @
429e8e0
...
@@ -82,7 +82,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -82,7 +82,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
},
{
},
{
fields
:
[
'name'
,
'email'
]
fields
:
[
'name'
,
'email'
]
}).
then
(
function
(
user
)
{
}).
then
(
function
(
user
)
{
return
user
.
update
Attributes
({
bio
:
'swag'
});
return
user
.
update
({
bio
:
'swag'
});
}).
then
(
function
(
user
)
{
}).
then
(
function
(
user
)
{
return
user
.
reload
();
return
user
.
reload
();
}).
then
(
function
(
user
)
{
}).
then
(
function
(
user
)
{
...
@@ -93,6 +93,32 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -93,6 +93,32 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
});
});
it
(
'should not set attributes that are not specified by fields'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
DataTypes
.
STRING
,
bio
:
DataTypes
.
TEXT
,
email
:
DataTypes
.
STRING
});
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
name
:
'snafu'
,
email
:
'email'
}).
then
(
function
(
user
)
{
return
user
.
update
({
bio
:
'heyo'
,
email
:
'heho'
},
{
fields
:
[
'bio'
]
});
}).
then
(
function
(
user
)
{
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'snafu'
);
expect
(
user
.
get
(
'email'
)).
to
.
equal
(
'email'
);
expect
(
user
.
get
(
'bio'
)).
to
.
equal
(
'heyo'
);
});
});
});
it
(
'updates attributes in the database'
,
function
(
done
)
{
it
(
'updates attributes in the database'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'user'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
username
:
'user'
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
to
.
equal
(
'user'
);
expect
(
user
.
username
).
to
.
equal
(
'user'
);
...
...
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