I'm trying to add an object to a relation in Parse, although the code gets exectued without any errors the relation does not appear in the backend, therefore the object was not saved.
PFObject *newContact = [PFObject objectWithClassName:@"Contact"];
[newContact saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
PFQuery *query = [PFQuery queryWithClassName:@"Trip"];
PFObject *trip = [query getObjectWithId:self.parseID];
PFRelation *rel = [trip relationForKey:@"contacts"];
[rel addObject:newContact];
contact.parseID = newContact.objectId;
}];
I've also checked if the PFObject trip
is correct and I get back the desired object with the corresponding id. Also the key contacts
is double-checked and correct.
The problem is that you never save the relation. You create the
PFRelation
within the block, add an object to it, and do nothing else with it... You never save it.Instead, try fetching the
trip
object and creating thePFRelation
outside of the save block, ex: