我有一个复合查询,如下所示。
- (PFQuery *)queryForPhotos {
if (![PFUser currentUser]) {
PFQuery *query = [PFQuery queryWithClassName:kPAPPhotoClassKey];
[query setLimit:0];
return query;
}
// Query for users with the same language level
PFQuery *sameLevelUsersQuery = [PFUser query];
[sameLevelUsersQuery whereKey:kWSUserLanguageLevelKey equalTo:[[PAPCache sharedCache] languageLevelForUser:[PFUser currentUser]]];
sameLevelUsersQuery.cachePolicy = kPFCachePolicyNetworkOnly;
sameLevelUsersQuery.limit = 1000;
PFQuery *photosFromSameLevelUsersQuery = [PFQuery queryWithClassName:kPAPPhotoClassKey];
[photosFromSameLevelUsersQuery whereKey:kPAPPhotoUserKey matchesQuery:sameLevelUsersQuery];
[photosFromSameLevelUsersQuery whereKeyExists:kPAPPhotoPictureKey];
[photosFromSameLevelUsersQuery whereKey:kWSUniversalIsDeletedKey notEqualTo:[NSNumber numberWithBool:YES]];
[photosFromSameLevelUsersQuery includeKey:kWSPhotoCommentObjectForTitleKey]; // THE INCLUDED KEY IN QUESTION
[photosFromSameLevelUsersQuery orderByDescending:@"createdAt"];
// A pull-to-refresh should always trigger a network request.
[photosFromSameLevelUsersQuery setCachePolicy:kPFCachePolicyNetworkOnly];
return photosFromSameLevelUsersQuery;
}
如果我将此行留在:
[photosFromSameLevelUsersQuery includeKey:kWSPhotoCommentObjectForTitleKey]; // THE INCLUDED KEY IN QUESTION
然后我只得到 1 个在该字段中包含 commentObject 的 photoObject。但是,数据库中(当前)26 张照片中有 3 张在该字段中有评论对象,因此我应该在该字段中获得 3 张带有某些内容的照片。一个commentObject 确实加载了它的所有字段。
但是,如果我省略了该includeKey
行,那么在该字段中包含某些内容的所有 3 个 photoObjects 都会在该字段中返回一个 commentObject。但是,在这种情况下,对象是空的,我必须调用fetchIfNeeded
来检索它们的数据。
如果我可以第一次以正确的方式加载数据,我宁愿不这样做,并且必须在回调时重新加载 tableView。
有任何想法吗?