You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: replacing existing object leaves old properties #4246
When saving an existing object with new properties, if the new object doesn't contain properties that the old object did, these properties are not removed.
Steps to reproduce
In Cloud Code, if we do:
var o = new Parse.Object('Class');
o.id = 'id';
o.set(key1, value1);
o.set(key2, value2);
o.save()
And then later:
var o = new Parse.Object('Class');
o.id = 'id';
o.set(key1, value1);
o.save()
o.get(key2) is still set as value2, instead of null.
@doender Saving an object creates/updates an object as needed. The initial save operation will create a new object with completely new values, subsequent saves will only pass changes. Considering that the only thing you changed in your example was key1 that's the only key/value pair that was changed upstream. If you set key2 to null then you would be getting your expected result.
Completely overriding an object on each save (especially if it's an incomplete local copy) is definitely not the intended functionality of save. If you're having issues keeping track of values in objects which are partially complete (via setting the id and one field like above) you can always use a fetch to get the current server copy and work from there. You can check out the JS sdk guide and the Cloud code guide for other examples as well.
Activity
montymxb commentedon Oct 12, 2017
@doender Saving an object creates/updates an object as needed. The initial save operation will create a new object with completely new values, subsequent saves will only pass changes. Considering that the only thing you changed in your example was
key1that's the only key/value pair that was changed upstream. If you setkey2tonullthen you would be getting your expected result.Completely overriding an object on each save (especially if it's an incomplete local copy) is definitely not the intended functionality of save. If you're having issues keeping track of values in objects which are partially complete (via setting the id and one field like above) you can always use a fetch to get the current server copy and work from there. You can check out the JS sdk guide and the Cloud code guide for other examples as well.