LastMove
LastMove

Reputation: 2482

Parse.com cloud code dirty relation

I am using Parse Cloud code hooks (beforeSave). My object has a relation and I need to know which objects where added to this relation. My problem is exactly the same than here. I want to be able to do this :

var op = myObject.op('toto');

//Get all add op in relation toto
var added = op.added();

//Get all remove op in relation toto
var deleted = op.removed();

added.forEach(function(pointer) {
     //Do something with pointer

     //If you need value on pointer
     pointer.fetch(function(objectFetched) {
         //Do something with object
     });
});
}

But that is not working anymore because

Result: TypeError: Object [object Object] has no method 'added'

How can I do now to know which objects was added to the relation ?

Upvotes: 0

Views: 160

Answers (1)

Mo Nazemi
Mo Nazemi

Reputation: 2717

Unfortunately there is no information on this in Parse documentation. I had to poke through their source code to figure out how to do the exact thing for my Cloud Code. Anyway, you can get an Array of objectIds that are being added to a Relation like this:

var added = request.object.op("toto").relationsToAdd;

If you want to find the ones being removed, just replace relationsToAdd with relationsToRemove

Upvotes: 3

Related Questions