Search code examples
androidparse-platformpinning

In Parse, does unpinning objects from local datastore also remove the objects they point?


In the Parse SDK docs, it states that pinning an object that points to another object, will also pin that target object:https://parse.com/docs/android_guide#localdatastore-pin

As with saving, this recursively stores every object and file that gameScore points to, if it has been fetched from the cloud. Whenever you save changes to the object, or fetch new changes from Parse, the copy in the datastore will be automatically updated, so you don't have to worry about it.

What it doesn't state though, is how do you later unpin the first object, as well as any objects it points to? (basically reverse the transaction), along with deleting those objects from the cloud?

Would You:

A.) unpin all objects that reference the first object, then use DeleteEventually to delete the target object

or

B.) unpin all objects first, which then will delete the target object automatically?

Also, if an object is pinned in the datastore, but is also saved to the cloud (never unpinned), does unpinning it also delete it from the cloud? or does it need to first either be unpinned then deleted, or deleted/unpinned?

EDIT:

If I understand Fosco's reply, I would need to do something like the following:

final ParseQuery<ParseObject> findMoves = ParseQuery.getQuery("bjjMatchMoves");
findMoves.fromPin("BJJMove");
findMoves.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(final List<ParseObject> moves, final com.parse.ParseException e) {

    if (e == null) {

    // First, unpin all objects that reference the main object, which should Remove the main object as well.
    ParseObject.unpinAllInBackground("BJJMove", moves, new DeleteCallback() {
        public void done(ParseException e) {
        if (e != null) {
            // There was some error.
            return;
        }
        // objects have Now been unpinned. Now Delete them from the cloud

        ParseObject.deleteAllInBackground(moves, new DeleteCallback() {
            public void done(ParseException e) {
                if (e != null) {
                    // There was some error.
                    return;
                }

                // objects have Now been unpinned and deleted, remove the main object from the cloud
            }
        });
        }
    });
    }
    }
});

Solution

  • So, first things first... un-pinning is not going to delete the object from 'the cloud'. It's just going to remove the locally cached version.

    Secondly, yes, if you unpin the root object that references other objects, the other objects will also be unpinned (unless they've been separately pinned).

    If you want to delete an object, you should delete it, which should also unpin it.