ios - Parse PFRelation complex search -
i'm building ios app parse has few complex queries , running trouble pfrelation.
it's social network website people submit articles. can follow other users , see articles submitted. can search based on topics.
this code have
pfquery* query = [pfquery querywithclassname:@"article"]; //remove articles user has seen or submitted [query wherekey:@"likedby" notequalto:currentuser]; //'likedby' relation [query wherekey:@"dislikedby" notequalto:currentuser]; //'dislikedby' relation [query wherekey:@"submittedby" notequalto:currentuser]; //'submittedby' relation [query wherekey:@"tagarray" containedin:tags]; [query orderbydescending:@"createdat"]; pfrelation* relation = [currentuser relationforkey:@"following"]; //following relation user pfquery* followingquery = [relation query]; [followingquery findobjectsinbackgroundwithblock:^(nsarray* results, nserror* error) { //results first query list of people user following [query wherekey:@"submittedby" containedin:results]; //submitted relation on article [query findobjectsinbackgroundwithblock:^(nsarray* results, nserror* error) { /* return items match tags set above. however, if there no tags, not articles match "submittedby" above. empty */ completion(results); }]; }]; }
thank time reading this.
i able resolve issue creating subquery:
pfquery* query = [pfquery querywithclassname:@"article"]; //remove articles user has seen or submitted [query wherekey:@"likedby" notequalto:currentuser]; //'likedby' relation [query wherekey:@"dislikedby" notequalto:currentuser]; //'dislikedby' relation [query wherekey:@"submittedby" notequalto:currentuser]; //'submittedby' relation [query wherekey:@"tagarray" containedin:tags]; // create array hold of queries nsmutablearray* queryarray = [nsmutablearray arraywithcapacity:10]; pfrelation* relation = [currentuser relationforkey:@"following"]; //following relation user pfquery* followingquery = [relation query]; [followingquery findobjectsinbackgroundwithblock:^(nsarray* results, nserror* error) { //results first query list of people user following (pfobject* user in results) { //create new query each result , add query array pfquery* querysub = [pfquery querywithclassname:@"app"]; [querysub wherekey:@"submittedby" equalto:user]; [queryarray addobject:querysub]; } //query of queries @ once pfquery* finalquery = [pfquery orquerywithsubqueries:queryarray]; [finalquery findobjectsinbackgroundwithblock:^(nsarray* results, nserror* error) { //note: cannot sort via query subqueries, had sort results array when completed …... }]; }]; }
Comments
Post a Comment