NSPredicate *predicate=[NSPredicate predicateWithFormat:@"(UserId==%@)",[defaluts objectForKey:@"objectId"]];
PFQuery *frndquery=[PFQuery queryWithClassName:@"FriendsDetails" predicate:predicate];
[frndquery orderByDescending:@"lastdate"];
[frndquery whereKey:@"BlockStatus" equalTo:@"No"];
NSArray *arrquery=[frndquery findObjects];
for (PFObject *frndids in arr){
PFRelation *relation=[frndids relationforKey:@"ChatRelation"];
NSArray *arrids=[NSArray arrayWithObjects:[frndids objectForKey:@"UserId"],[frndids objectForKey:@"ConversationID"], nil];
PFQuery *statusQuery = [relation query];
[statusQuery orderByDescending:@"createdAt"];
[statusQuery whereKey:@"Deletechat" notContainedIn:arrids];
statusQuery.limit = [[NSNumber numberWithInt:1] intValue];
NSArray *arrforrelationobjects=[statusQuery findObjects];}
I want to find all objects when we retrieve the objects from the first query itself. Please solve my problem
There is a method you can use to
include
properties which are pointer values. You cannot use theinclude
method with relations. What I do instead is use a Cloud Code function to aggregate the results I want into a JSON object and return that object.See the
fetchPostDetails
function in the following script.https://github.com/brennanMKE/PostThings/blob/master/Parse/PostThings/cloud/main.js
It fetches items are relation objects such as tags and likes which happen to be
User
objects which are relations to thePost
class. There are also comments which are referenced as a pointer back to the post from each comment. ThefetchPostTags
andfetchPostLikes
methods show how to fetch those relations and populate the JSON object which is holding all of the results. You need to deploy those Cloud Code update and then access it as a function from the iOS side. The results will come back as an NSDictionary with values for posts, tags, likes and comments. The posts are an array of Post objects. The tags, likes and comments are NSDictionary objects which have the postId as the key to access the array of Parse objects.This way one call to the function will get you want you need.
I've included some of the code below as a reference in case what is on GitHub changes.