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 09ced4d1
authored
Oct 22, 2018
by
Justin Kalland
Committed by
Sushant
Oct 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): return deep cloned value for toJSON (#10058)
1 parent
5dc314b5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletions
lib/model.js
test/unit/instance/to-json.test.js
lib/model.js
View file @
09ced4d
...
...
@@ -4201,7 +4201,7 @@ class Model {
* @returns {Object}
*/
toJSON
()
{
return
_
.
clone
(
return
_
.
clone
Deep
(
this
.
get
({
plain
:
true
})
...
...
test/unit/instance/to-json.test.js
View file @
09ced4d
...
...
@@ -22,5 +22,24 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const
json2
=
user
.
toJSON
();
expect
(
json2
).
to
.
have
.
property
(
'name'
).
and
.
be
.
equal
(
'my-name'
);
});
it
(
'returns clone of JSON data-types'
,
()
=>
{
const
User
=
current
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
permissions
:
DataTypes
.
JSON
});
const
user
=
User
.
build
({
name
:
'my-name'
,
permissions
:
{
admin
:
true
,
special
:
'foobar'
}
});
const
json
=
user
.
toJSON
();
expect
(
json
)
.
to
.
have
.
property
(
'permissions'
)
.
that
.
does
.
not
.
equal
(
user
.
permissions
);
json
.
permissions
.
admin
=
false
;
expect
(
user
.
permissions
)
.
to
.
have
.
property
(
'admin'
)
.
that
.
equals
(
true
);
});
});
});
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