Ios 带PFUser和友谊限制的查询询问
我有一个应用程序,用户可以在其中撰写意见,只有他们的朋友才能在时间轴中看到并发表评论(在名为“OpTimelineTableViewController”的子类中)。但我有一个疑问,如何正确地进行这个限制查询,即使我以前尝试过解决方案,但没有更多的结果。。。(我开始向您介绍我的数据模型): “用户”表(是Parse提供的内置类) “意见”表: 目的 森德里德;指针用户表 内容;串 更新数据;(默认情况下提供) 创建数据;(默认情况下提供) “朋友”表: friendId1=指针用户表 friendId2=指针用户表 status=可以接受“确认”、“挂起”或“拒绝”的字符串 updatedAt=(默认情况下提供) createdAt=(默认情况下提供) 这是我尝试过的代码的主要重要部分:Ios 带PFUser和友谊限制的查询询问,ios,objective-c,parse-platform,pfquery,pfuser,Ios,Objective C,Parse Platform,Pfquery,Pfuser,我有一个应用程序,用户可以在其中撰写意见,只有他们的朋友才能在时间轴中看到并发表评论(在名为“OpTimelineTableViewController”的子类中)。但我有一个疑问,如何正确地进行这个限制查询,即使我以前尝试过解决方案,但没有更多的结果。。。(我开始向您介绍我的数据模型): “用户”表(是Parse提供的内置类) “意见”表: 目的 森德里德;指针用户表 内容;串 更新数据;(默认情况下提供) 创建数据;(默认情况下提供) “朋友”表: friendId1=指针用户表 frien
- (void)loadOpinions {
PFQuery *opinionQuery = [PFQuery queryWithClassName:@"Opinion"];
[opinionQuery orderByDescending:@"createdAt"];
[opinionQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// Array declared as property in the ".h" that contains Opinion objects
self.opinionArray = [[NSArray alloc] initWithArray:objects];
}
[self.tableView reloadData];
[self.refreshControl endRefreshing];
}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.opinionArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
OpinionTimelineCell *opCell = [tableView dequeueReusableCellWithIdentifier:@"OpTimelineCell" forIndexPath:indexPath];
// self.tempOpObj is an instance of PFObject declared in the ".h" that contains opinion object (for the appropriate index) contained in the opinionArray
self.tempOpObj = [self.opinionArray objectAtIndex:indexPath.row];
// Now I query "User" table to retrieve all users that have posted Opinions:
PFQuery *UserOpinionQuery = [PFUser query];
// I do a restriction between users that are contained in the "Opinion" table:
[UserOpinionQuery whereKey:@"objectId" equalTo:[[self.tempOpObj objectForKey:@"senderId"]objectId]];
[UserOpinionQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// "userOpInfo" is an instance of PFUser declared in the ".h" that contains the last of object retrieved in "objects":
self.userOpInfo = [objects lastObject];
opCell.opinionUsername.text = self.userOpInfo.username;
}
}];
opCell.opinionContent.text = [self.tempOpObj objectForKey:@"content"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"mm-DD-yyyy";
opCell.opinionDate.text = [dateFormatter stringFromDate:self.tempOpObj.createdAt];
[opCell setSelectionStyle:UITableViewCellSelectionStyleNone];
// ? Query to restrict visible Opinion posts only if users are a current user friend:
PFQuery *restrictFriendQuery = [PFQuery queryWithClassName:@"Friends"];
[restrictFriendQuery whereKey:@"friendId1" equalTo:[PFUser currentUser]];
[restrictFriendQuery whereKey:@"friendId2" equalTo:[self.userOpInfo objectId]];
[restrictFriendQuery whereKey:@"status" equalTo:@"Confirm"];
// Is that way the best ??
[restrictFriendQuery findObjects];
return opCell;
}
在这一点上,我的问题是:如何通过知道单元格的数量取决于opinionArray中包含的意见数量来知道我在其他查询之前做了什么,或者简单地说:如何通过限制当前用户朋友的意见来进行查询
(注意:我已在viewDidLoad中实现了方法[self.performSelector(LoadObservices)…..,以获取信息)
我的代码似乎不清楚我很好,这就是为什么我没有找到一个简单的方法来做它
有人可以帮助解决这个问题吗?我会使用你的朋友表来帮助管理请求和批准流程。我会使用云代码,以便在批准友谊时,将朋友添加到用户表上的关系中
通过执行此操作,您将能够从当前用户获得一个包含其所有好友的查询。这可以与意见查询一起使用,以将结果限制为好友用户创建的行。我是否必须在用户表中创建一个包含所有用户好友的数组“friend”列?是的,我会这样做