我有一个具有多个不同属性的 Parse 事件类。其中一个属性恰好包含指向照片对象的指针。我需要创建一个查询,为我提供所有照片,这些照片嵌入在也需要查询的事件对象中。
方法 – whereKey:matchesKey:inQuery:
似乎应该有效,但由于某些原因它不是。这是我尝试过的:
PFQuery *activityQuery = [PFQuery queryWithClassName:@"activityClass"];
[activityQuery whereKeyExists:@"photo"];
PFQuery *photoQuery = [PFQuery queryWithClassName:@"photoClass"];
[photoQuery whereKey:@"objectId" matchesKey:@"photo" inQuery:statisticsQuery];
[photoQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
}
}];
要点是我需要创建一个查询来返回对象,这些对象嵌入在不同的类对象中。当我运行上面的代码时,我只是没有在对象数组中得到任何结果。如果它正常工作,那肯定也应该有一些东西。
关于如何实现此目标的任何想法?
最佳答案
您可以在第一个查询中包含照片:
PFQuery *activityQuery = [PFQuery queryWithClassName:@"activityClass"];
[activityQuery whereKeyExists:@"photo"];
[activityQuery includeKey:@"photo"];
[activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// You now have the activityClass objects that has photos,
// and the photoClass objects have been fetched as well.
// Iterate through the activityClass objects and get the photos from them
}
}];
关于ios - 创建一个组合的解析查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23284186/