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 4585ba41
authored
Aug 24, 2015
by
Emil Janitzek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(model.set): Fixed model set for JSON with dot.separated key
1 parent
a2cb0c13
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
1 deletions
changelog.md
lib/instance.js
test/unit/instance/changed.test.js
changelog.md
View file @
4585ba4
# Next
-
[
FIXED
]
Calling set with dot.separated key on a JSON/JSONB attribute will not flag the entire object as changed
[
#4379
](
https://github.com/sequelize/sequelize/pull/4379
)
# 3.9.0
-
[
ADDED
]
beforeRestore/afterRestore hooks
[
#4371
](
https://github.com/sequelize/sequelize/issues/4371
)
-
[
ADDED
]
Map raw fields back to attributes names when using
`mapToModel`
or
`returning`
[
#3995
](
https://github.com/sequelize/sequelize/pull/3995
)
...
...
lib/instance.js
View file @
4585ba4
...
...
@@ -322,8 +322,11 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
// If attribute is not in model definition, return
if
(
!
this
.
_isAttribute
(
key
))
{
if
(
key
.
indexOf
(
'.'
)
>
-
1
&&
this
.
Model
.
_isJsonAttribute
(
key
.
split
(
'.'
)[
0
]))
{
var
previousDottieValue
=
Dottie
.
get
(
this
.
dataValues
,
key
);
if
(
!
_
.
isEqual
(
previousDottieValue
,
value
))
{
Dottie
.
set
(
this
.
dataValues
,
key
,
value
);
this
.
changed
(
key
,
true
);
this
.
changed
(
key
.
split
(
'.'
)[
0
],
true
);
}
}
return
;
}
...
...
test/unit/instance/changed.test.js
View file @
4585ba4
...
...
@@ -94,5 +94,61 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
user
.
set
(
'meta'
,
meta
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
true
);
});
it
(
'should return true for JSON dot.separated key with changed values'
,
function
()
{
var
user
=
this
.
User
.
build
({
meta
:
{
city
:
'Stockholm'
}
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'meta.city'
,
'Gothenburg'
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
true
);
});
it
(
'should return false for JSON dot.separated key with same value'
,
function
()
{
var
user
=
this
.
User
.
build
({
meta
:
{
city
:
'Gothenburg'
}
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'meta.city'
,
'Gothenburg'
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
false
);
});
it
(
'should return true for JSON dot.separated key with object'
,
function
()
{
var
user
=
this
.
User
.
build
({
meta
:
{
address
:
{
street
:
'Main street'
,
number
:
'40'
}
}
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'meta.address'
,
{
street
:
'Second street'
,
number
:
'1'
}
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
true
);
});
it
(
'should return false for JSON dot.separated key with same object'
,
function
()
{
var
user
=
this
.
User
.
build
({
meta
:
{
address
:
{
street
:
'Main street'
,
number
:
'40'
}
}
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'meta.address'
,
{
street
:
'Main street'
,
number
:
'40'
}
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
false
);
});
});
});
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