不要怂,就是干,撸起袖子干!

Commit 09ced4d1 by Justin Kalland Committed by Sushant

fix(model): return deep cloned value for toJSON (#10058)

1 parent 5dc314b5
......@@ -4201,7 +4201,7 @@ class Model {
* @returns {Object}
*/
toJSON() {
return _.clone(
return _.cloneDeep(
this.get({
plain: true
})
......
......@@ -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);
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!