我发布的查询中的每个人都好,我正在尝试检索所有帖子和PfUserCurrent所有与PfUserCurrent分享友谊的人的帖子。
查询工作正常,但我只有一个问题,查询显示了CurrentUser之友的所有帖子,但没有告诉我CurrentUser发送的那些...我尝试了几次尝试但我无法修复这......你能解释我错在哪里吗?
-(void)QueryForPost {
PFQuery *QueryForFriend=[PFQuery queryWithClassName:@"Friendships"];
[QueryForFriend whereKey:@"To_User" equalTo:[PFUser currentUser]];
[QueryForFriend whereKey:@"STATUS" equalTo:@"Confirmed"];
PFQuery *QueryYES = [PFQuery queryWithClassName:@"Post"];
[QueryYES whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:YES]];
[QueryYES whereKey:@"UserSelected" equalTo:[PFUser currentUser]];
PFQuery *QueryNO = [PFQuery queryWithClassName:@"Post"];
[QueryNO whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:NO]];
[QueryNO whereKey:@"Author" matchesKey:@"From_User" inQuery:QueryForFriend];
PFQuery *query = [PFQuery orQueryWithSubqueries:@[QueryYES,QueryNO]];
[query includeKey:@"Author"];
[query orderByDescending:FF_CREATEDAT];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
if (!error) {
NSLog(@"%@", results);
ArrayforPost = [[NSMutableArray alloc] init];
for (PFObject *object in results) {
[ArrayforPost addObject:object];
}
[self.FFTableView reloadData];
}
}];
}
答案 0 :(得分:4)
经过与@rory的长时间讨论后,我们来到了正确的答案:
-(void)QueryForPost {
PFQuery *QueryForFriend=[PFQuery queryWithClassName:@"Amicizie"];
[QueryForFriend whereKey:@"A_User" equalTo:[PFUser currentUser]];
[QueryForFriend whereKey:@"STATO" equalTo:@"Confermato"];
[QueryForFriend includeKey:@"Da_User"];
PFQuery *QueryYES = [PFQuery queryWithClassName:@"Post"];
[QueryYES whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:YES]];
[QueryYES whereKey:@"Scelti" equalTo:[PFUser currentUser]];
PFQuery *normalPostByFriends = [PFQuery queryWithClassName: @"Post"];
[normalPostByFriends whereKey: @"FLASH_POST" equalTo: [NSNumber numberWithBool: NO]];
[normalPostByFriends whereKey: @"Utente" matchesKey:@"Da_User" inQuery:QueryForFriend];
PFQuery *normalPostByUser = [PFQuery queryWithClassName:@"Post"];
[normalPostByUser whereKey: @"FLASH_POST" equalTo: [NSNumber numberWithBool: NO]];
[normalPostByUser whereKey: @"Utente" equalTo: [PFUser currentUser]];
PFQuery *query = [PFQuery orQueryWithSubqueries:@[QueryYES,normalPostByFriends,normalPostByUser ]];
[query includeKey:@"Author"];
[query orderByDescending:FF_CREATEDAT];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
if (!error) {
NSLog(@"%@", results);
ArrayforPost = [[NSMutableArray alloc] init];
for (PFObject *object in results) {
[ArrayforPost addObject:object];
}
[self.FFTableView reloadData];
}
}];
}
通过进行另一个查询来显示当前用户的正常帖子并修改QueryForFriend
以获得正确的查询来处理问题