我无法在 Parse 中保存 PFRelation。我有一条消息 PFObject 并希望将其添加到 PFUser 类中的 PFRelation receivedMessages 中。代码如下。一切都在努力建立这种关系。我已经很好地设置了用户对象,NSLog 显示了正确的用户,但似乎[sendtoUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)根本没有被调用,因为控制台中没有显示“保存的关系”。有人可以帮忙吗?谢谢
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