I'm building an iOS app with Parse that has a few complex queries and running into some trouble with PFRelation.
It's a social network website where people submit articles. You can follow other users and see the articles they submitted. You can also search based on topics.
This is the code I have
PFQuery* query = [PFQuery queryWithClassName:@"Article"];
//remove articles this user has seen or submitted
[query whereKey:@"likedBy" notEqualTo:currentUser]; //'likedBy' is a relation
[query whereKey:@"dislikedBy" notEqualTo:currentUser]; //'dislikedBy' is a relation
[query whereKey:@"submittedBy" notEqualTo:currentUser]; //'submittedBy' is a relation
[query whereKey:@"tagArray" containedIn:tags];
[query orderByDescending:@"createdAt"];
PFRelation* relation = [currentUser relationForKey:@"following"]; //following is a relation for the user
PFQuery* followingQuery = [relation query];
[followingQuery findObjectsInBackgroundWithBlock:^(NSArray* results, NSError* error) {
//results from this first query is the list of people the user is following
[query whereKey:@"submittedBy" containedIn:results]; //submitted by is a relation on the article
[query findObjectsInBackgroundWithBlock:^(NSArray* results, NSError* error) {
/* This will return all the items that match the tags set above.
However, if there are no tags, I do not get the articles
that match the "submittedBy" above. It is empty */
completion(results);
}];
}];
}
Thank you for your time reading this.
I was able to resolve this issue by creating a subquery: