Skip to content

Commit dfbe606

Browse files
committed
Strips all operations from result
- fix for #1606
1 parent 5b4638b commit dfbe606

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

spec/CloudCode.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,29 @@ describe('Cloud Code', () => {
751751
done();
752752
})
753753
});
754+
755+
it_exclude_dbs(['postgres'])('should not include relation op (regression test for #1606)', done => {
756+
var TestObject = Parse.Object.extend('TestObject');
757+
var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged');
758+
let testObj;
759+
Parse.Cloud.beforeSave('BeforeSaveChanged', (req, res) => {
760+
var object = req.object;
761+
object.set('before', 'save');
762+
testObj = new TestObject();
763+
testObj.save().then(() => {
764+
object.relation('testsRelation').add(testObj);
765+
res.success();
766+
})
767+
});
768+
769+
let object = new BeforeSaveObject();
770+
object.save().then((objectAgain) => {
771+
// Originally it would throw as it would be a non-relation
772+
expect(() => { objectAgain.relation('testsRelation') }).not.toThrow();
773+
done();
774+
}).fail((err) => {
775+
console.error(err);
776+
done();
777+
})
778+
});
754779
});

src/RestWrite.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,15 @@ RestWrite.prototype.updateResponseWithData = function(response, data) {
916916
Object.keys(data).forEach(fieldName => {
917917
let dataValue = data[fieldName];
918918
let responseValue = response[fieldName];
919-
if (!clientSupportsDelete && dataValue && dataValue.__op === 'Delete') {
919+
920+
response[fieldName] = responseValue || dataValue;
921+
922+
// Strips operations from responses
923+
if (response[fieldName] && response[fieldName].__op) {
920924
delete response[fieldName];
921-
} else {
922-
response[fieldName] = responseValue || dataValue;
925+
if (clientSupportsDelete && dataValue.__op == 'Delete') {
926+
response[fieldName] = dataValue;
927+
}
923928
}
924929
});
925930
return response;

0 commit comments

Comments
 (0)