Skip to content

Bug: replacing existing object leaves old properties #4246

Closed

Description

@doender

Issue Description

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.

Environment Setup

  • Server

    • parse-server version: 2.6.3
    • Localhost or remote server? Localhost
  • Database

    • MongoDB version: 3.0.15

Activity

  1. montymxb commented on Oct 12, 2017

    @montymxb
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions