0

I am trying to grab results from parse table by following query

NSInteger skip = self.objectsArray.count;

PFQuery *innerQuery = [PFUser query];
[innerQuery whereKey:@"objectId" equalTo:[PFUser currentUser].objectId];

PFQuery *query = [PFQuery queryWithClassName:@"HubObjects"];
[query whereKey:@"isActive" equalTo:[NSNumber numberWithBool:YES]];
[query whereKey:@"Location" nearGeoPoint:self.location withinMiles:200];
[query whereKey:@"Hub" equalTo:self.hub];
[query whereKey:@"RTUser" doesNotMatchQuery:innerQuery];
[query orderByDescending:@"Points"];

query.skip = skip;
query.limit = 3;
[query findObjectsInBackgroundWithBlock:^(NSArray *HubObjects, NSError *error) {
    if (!error) {
        //do success stuff
    } else {
        //do error stuff
    }
}];

It says basically give me an array of objects within certain limits, important to note are query.limit, query.skip and orderByDescending

this returns as expected but with orderByDescending it gives me objects with "Lowest Points" where as it should be returning objects with highest points first also further results (pagination) gives duplicate results of the first time.

I tried using orderByAscending which gives correct behaviour (Lowest point objects first and on further pagination gives new objects with higher points), I also tried removing the limit constrain which gave the whole list of objects in correct order (highest to lowest Points)

the problem is How can i get results paginated (with limit) in order desired (highest to lowest) and without duplication?

24
  • Can you not just use [query whereKey:@"RTUser" notEqualTo:[PFUser currentUser]]; to simplify it (remove the inner query). Commented Jul 30, 2014 at 15:25
  • its a PFRelation field, I got it from documentation, besides this is not the problem Commented Jul 30, 2014 at 15:27
  • No worries, yeah, just looking at the problem now. Just thought I'd add it as a comment :) Commented Jul 30, 2014 at 15:27
  • Note, I didn't down vote. Commented Jul 30, 2014 at 15:28
  • 2
    Used your advice and tried querying by hiding all constraints and then adding one by one, it seems to me problem is with [query whereKey:@"Location" nearGeoPoint:self.location withinMiles:200]; PFGeoPoint, this one is causing order to mess up and giving duplicate results, please advice further coarse of action Commented Jul 30, 2014 at 18:03

1 Answer 1

3

After a lot of investigating. :-)

It seems the geopoint search is overriding the sort order. I thought this might have been the case but I couldn't find the docs I read about it.

I don't think there will be a way around this using an iOS query.

You're best solution would probably be to write a cloud code function to return the information you need.

Otherwise remove the geopoint constraint and work it in after.

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.