Skip to content

Commit a35c9c5

Browse files
authored
fix(Object): _mergeMagicFields before set attributes when new Object with parse option (#397)
1 parent e376f10 commit a35c9c5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = function(AV) {
5050
attributes = attributes || {};
5151
if (options && options.parse) {
5252
attributes = this.parse(attributes);
53+
attributes = this._mergeMagicFields(attributes);
5354
}
5455
var defaults = AV._getValue(this, 'defaults');
5556
if (defaults) {
@@ -375,6 +376,7 @@ module.exports = function(AV) {
375376
delete attrs[attr];
376377
}
377378
});
379+
return attrs;
378380
},
379381

380382
/**
@@ -652,8 +654,6 @@ module.exports = function(AV) {
652654
// Run validation.
653655
this._validate(attrs, options);
654656

655-
this._mergeMagicFields(attrs);
656-
657657
options.changes = {};
658658
var escaped = this._escapedAttributes;
659659
var prev = this._previousAttributes || {};

test/object.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ describe('Objects', function(){
8989
});
9090
});
9191

92+
it('toJSON and parse', () => {
93+
const json = gameScore.toJSON();
94+
json.objectId.should.eql(gameScore.id);
95+
json.id.should.eql(gameScore.get('id'));
96+
json.score.should.eql(gameScore.get('score'));
97+
const parsedGameScore = new GameScore(json, { parse: true });
98+
parsedGameScore.id.should.eql(gameScore.id);
99+
parsedGameScore.get('id').should.eql(gameScore.get('id'));
100+
parsedGameScore.get('score').should.eql(gameScore.get('score'));
101+
});
102+
92103
it('should create a User',function(){
93104
var User = AV.Object.extend("User");
94105
var u = new User();

0 commit comments

Comments
 (0)