如何获得关系的另一面

时间:2014-09-28 20:27:08

标签: ios objective-c parse-platform

我正在使用parse作为我的应用程序的数据库。 我在应用程序中创建两个对象之间的许多关系。取自Parse docs

// Create the post
PFObject *myPost = [PFObject objectWithClassName:@"Post"];
myPost[@"title"] = @"I'm Hungry";
myPost[@"content"] = @"Where should we go for lunch?";

// Create the comment
PFObject *myComment = [PFObject objectWithClassName:@"Comment"];
myComment[@"content"] = @"Let's do Sushirrito.";

// Add a relation between the Post and Comment
myComment[@"parent"] = myPost;

// This will save both myPost and myComment
[myComment saveInBackground];

保存关系后,我如何从myPost对象获取myComment对象? 感谢

1 个答案:

答案 0 :(得分:1)

这不是双向关系。您不会从myPost对象获取myComment对象。您将获得myComment对象,从查询“类”以查找“父”设置为myPost的注释。

PFQuery *query = [PFQuery queryWithClassName:@"Comment"];
[query whereKey:@"parent" equalTo:myPost];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    ...
}];
相关问题