Skip to content

Commit

Permalink
Strips all operations from result
Browse files Browse the repository at this point in the history
- fix for #1606
  • Loading branch information
flovilmart committed Jul 12, 2016
1 parent 5b4638b commit dfbe606
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
25 changes: 25 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,29 @@ describe('Cloud Code', () => {
done();
})
});

it_exclude_dbs(['postgres'])('should not include relation op (regression test for #1606)', done => {
var TestObject = Parse.Object.extend('TestObject');
var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged');
let testObj;
Parse.Cloud.beforeSave('BeforeSaveChanged', (req, res) => {
var object = req.object;
object.set('before', 'save');
testObj = new TestObject();
testObj.save().then(() => {
object.relation('testsRelation').add(testObj);
res.success();
})
});

let object = new BeforeSaveObject();
object.save().then((objectAgain) => {
// Originally it would throw as it would be a non-relation
expect(() => { objectAgain.relation('testsRelation') }).not.toThrow();
done();
}).fail((err) => {
console.error(err);
done();
})
});
});
11 changes: 8 additions & 3 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,15 @@ RestWrite.prototype.updateResponseWithData = function(response, data) {
Object.keys(data).forEach(fieldName => {
let dataValue = data[fieldName];
let responseValue = response[fieldName];
if (!clientSupportsDelete && dataValue && dataValue.__op === 'Delete') {

response[fieldName] = responseValue || dataValue;

// Strips operations from responses
if (response[fieldName] && response[fieldName].__op) {
delete response[fieldName];
} else {
response[fieldName] = responseValue || dataValue;
if (clientSupportsDelete && dataValue.__op == 'Delete') {
response[fieldName] = dataValue;
}
}
});
return response;
Expand Down

0 comments on commit dfbe606

Please sign in to comment.