我想我把这个场景复杂化了。我正在处理多对多情况下的连接表。
如果我找到一个连接,我想删除它,如果我没有找到,我想添加它。
添加一个新的连接工作正常。想不通怎么删。。
这是我的代码。如果有人发现任何错误 - 或更好的方法,请提出建议。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
//Create query for all current user objects
PFQuery *query = [PFQuery queryWithClassName:@"DDPeopleJoin"];
[query whereKey:@"parseUser" equalTo:[PFUser currentUser]];
[query whereKey:@"serviceKey" equalTo:[currentService valueForKey:@"serviceKey"]];
[query whereKey:@"personKey" equalTo:[currentPerson valueForKey:@"personKey"]];
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
// Run the query - if there is an object delete it otherwise, go to JoinPeople
allDeadPeople = [NSMutableArray new];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
if (!objects) {
NSLog(@"New Person");
[self joinPeople];
return;
}
NSLog(@"Found a match, erase them");
for (PFObject *object in objects) {
[object deleteInBackground];
}
[self refreshJoins:self];
}
}];
}