我正在将解析用作我的应用程序的数据库。
我正在应用程序中创建两个对象之间的许多关系。取自解析文档
// 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对象?
谢谢
最佳答案
这不是双向关系。您不会从myPost对象获取myComment对象。通过查询Comments类以获取其“父”设置为myPost的注释,将获得myComment对象。
PFQuery *query = [PFQuery queryWithClassName:@"Comment"];
[query whereKey:@"parent" equalTo:myPost];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
...
}];
关于ios - 如何获得关系的另一面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26089301/