2

I have a Post and a Comment class. I'm trying to save a comment, with pointer to the post object. I've got my post object's ID. Here is my code:

PFObject *comment = [PFObject objectWithClassName:@"Comment"];
comment[@"content"] = comment;
PFObject *post = [PFObject objectWithoutDataWithClassName:@"Post" objectId:postId];
comment[@"post"] = post;
[comment saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if(succeeded){
        //rest...
    }
}];

However, saving it immediately raises exception: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Found a circular dependency when saving.' at the client side.

I've also tried PFObject *post = [PFObject objectWithoutDataWithObjectId:postId too, which results in '+[PFObject parseClassName]: unrecognized selector sent to class error.

Post doesn't depend on a comment object in any way, (and even if it did, it's already a saved object (as the user is commenting on it) and a pointer should't cause it) why am I getting this error?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

1 Answers1

2

I use Parse often and I'm not sure why it is saying you have a circular dependency. It looks to me that your problem is these lines:

PFObject *comment = [PFObject objectWithClassName:@"Comment"];
comment[@"content"] = comment;

You are loading an object, then setting that object as the "content." Each time you load the comment object, you are saving the comment object within the parent object, creating a loop. Could you try rewriting this, and maybe make a new class that manages both posts and comments?

scott
  • 1,194
  • 7
  • 18