I'm trying to load objects from the online backend, as well as from my local datastore. Therefore I'm using two different queries. First the online query:
PFQuery *onlineQuery = [PFQuery queryWithClassName:@"Trip"];
[onlineQuery whereKey:@"users" equalTo:[PFUser currentUser]];
[onlineQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Trips loaded from server!");
} else {
NSLog(@"Could not load trips from server!");
[onlineQuery cancel];
}
}];
The query for local datastore looks like this:
PFQuery *localQuery = [PFQuery queryWithClassName:@"Trip"];
[localQuery whereKey:@"users" equalTo:[PFUser currentUser]];
[localQuery fromLocalDatastore];
[localQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// at this point the objects array is empty, but should contain objects
NSLog(@"Trips loaded from local datastore!");
}];
The problem is that if I do the online query it returns all objects related to the current user. But the local query returns 0 objects for the same user. I've also checked that the currentUser is not nil. If I remove the line [localQuery whereKey:@"users" equalTo:[PFUser currentUser]]; the local query returns all objects, that means they were saved succesfully. Also the method when saving an object to the local datastore returns that it was saved succesfully.
PFObject *newTrip = [PFObject objectWithClassName:@"Trip"];
PFRelation *rel = [newTrip relationForKey:@"users"];
[rel addObject:[PFUser currentUser]];
[newTrip pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// succeeded is YES, therefore saving was succesful
NSLog(@"Trip saved to local datastore");
}
}];