I am having trouble saving a PFRelation in Parse. I have a message PFObject and want to add this to a PFRelation receivedMessages in the PFUser class. Code is below. Everything works up to actually trying to create the relationship. I have set the user object fine, NSLog displays the correct user but it appears [sendtoUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) is not being called at all as "relation saved" is not displayed in the console. Could someone help please? Thanks
PFObject *message = [PFObject objectWithClassName:@“message”];
message[@“fromUser"]=[PFUser currentUser].username;
message[@“message"]=@"喵!";
message[@“read"]=@NO;
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@“message saved”);
PFQuery *usernameQuery = [PFUser query];
[usernameQuery whereKey:@"username" equalTo:[[self.friends objectAtIndex:index] username]];
[usernameQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFUser *sendtoUser = (PFUser *)objects[0];
NSLog(@"send to user: %@", sendtoUser.username); //this works
PFRelation *receivedMessages = [sendtoUser relationForKey:@"receivedMessages”];
[receivedMessages addObject:message];
[sendtoUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@“relation saved”); //this doesn’t display at all
}];//end save user relation block
}];//end username query block
}];//end save message block, this works