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 24a8ac33
authored
Dec 22, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(instance): set should use local passed options.attributes rather than global…
… options, closes #2012
1 parent
d136bf6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
lib/instance.js
test/instance/update.test.js
lib/instance.js
View file @
24a8ac3
...
@@ -265,7 +265,7 @@ module.exports = (function() {
...
@@ -265,7 +265,7 @@ module.exports = (function() {
}
}
// If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
// If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
if
(
options
.
raw
&&
!
(
this
.
options
&&
this
.
options
.
include
)
&&
!
(
this
.
options
&&
this
.
options
.
attributes
)
&&
!
this
.
Model
.
_hasBooleanAttributes
&&
!
this
.
Model
.
_hasDateAttributes
)
{
if
(
options
.
raw
&&
!
(
this
.
options
&&
this
.
options
.
include
)
&&
!
(
options
&&
options
.
attributes
)
&&
!
this
.
Model
.
_hasBooleanAttributes
&&
!
this
.
Model
.
_hasDateAttributes
)
{
if
(
Object
.
keys
(
this
.
dataValues
).
length
)
{
if
(
Object
.
keys
(
this
.
dataValues
).
length
)
{
this
.
dataValues
=
_
.
extend
(
this
.
dataValues
,
values
);
this
.
dataValues
=
_
.
extend
(
this
.
dataValues
,
values
);
}
else
{
}
else
{
...
@@ -276,8 +276,8 @@ module.exports = (function() {
...
@@ -276,8 +276,8 @@ module.exports = (function() {
}
else
{
}
else
{
// Loop and call set
// Loop and call set
if
(
this
.
options
.
attributes
)
{
if
(
options
.
attributes
)
{
keys
=
this
.
options
.
attributes
;
keys
=
options
.
attributes
;
if
(
this
.
Model
.
_hasVirtualAttributes
)
{
if
(
this
.
Model
.
_hasVirtualAttributes
)
{
keys
=
keys
.
concat
(
this
.
Model
.
_virtualAttributes
);
keys
=
keys
.
concat
(
this
.
Model
.
_virtualAttributes
);
}
}
...
...
test/instance/update.test.js
View file @
24a8ac3
...
@@ -68,6 +68,31 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -68,6 +68,31 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
}
}
it
(
'should update fields that are not specified on create'
,
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'
},
{
fields
:
[
'name'
,
'email'
]
}).
then
(
function
(
user
)
{
return
user
.
updateAttributes
({
bio
:
'swag'
});
}).
then
(
function
(
user
)
{
return
user
.
reload
();
}).
then
(
function
(
user
)
{
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'snafu'
);
expect
(
user
.
get
(
'email'
)).
to
.
equal
(
'email'
);
expect
(
user
.
get
(
'bio'
)).
to
.
equal
(
'swag'
);
});
});
});
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