4

I have a PFUser object with several PFRelation pointing to other objects. When I run the following code:

PFRelation *relation = [[PFUser currentUser] relationForKey:@"Relation"];
PFQuery *query = [relation query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
    NSLog(@"%@", objects);
}];

it works fine. However, when I want to do the same from the local data store:

PFRelation *relation = [[PFUser currentUser] relationForKey:@"Relation"];
PFQuery *query = [[relation query] fromLocalDataStore]; // !!!
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
    NSLog(@"%@", objects);
}];

it returns nothing, despite the fact I've pinned both my user and related objects with [myObject pinInBackground].

Why PFRelation queries does not support fromLocalDataStore? What I'm doing wrong?

Alexander Vasenin
  • 11,437
  • 4
  • 42
  • 70
  • Do the objects in the relation have any ACL set? LDS does not support ACL, however, with v1.6.4 of the SDK you can tell the LDS query to ignore the ACL. – Björn Kaiser Mar 08 '15 at 19:27
  • I am currently not sure if the SDK automatically pins objects from a relation, they also might not have been fetched completely from the server unless the query you do to fetch the object has an include:@"relationField". Have you just pinned the parent object or also separately the fetched objects from the relation? – Björn Kaiser Mar 08 '15 at 19:39
  • I'm pinning related objects separately – Alexander Vasenin Mar 08 '15 at 19:42
  • 1
    If anyone interested, I've ended up converting all my PFRelation objects to arrays of pointers to related PFObjects. – Alexander Vasenin Mar 16 '15 at 23:28

3 Answers3

1

I've created a bug report for this issue which is

escalated to the engineering team to investigate further

So it looks like it's a bug

In the meanwhile, I've converted all my PFRelations to arrays of pointers to related PFObjects. Not as fancy as PFRelation, but works fine with local data storage.

Update: parse solved the issue in Parse SDK v.1.7.3

Alexander Vasenin
  • 11,437
  • 4
  • 42
  • 70
0

It's a Parse bug. It can be also reproduced with Android SDK. I'm not sure on iOS, but on Android I have found a way how to make it work.

You need to have a Pointer in "related" classes to the ParseObject which has Relations.

In your case, you have a PFUser which has several PFRelations. If you add a PFPointer to your PFUser in "related" classes, query from the local datastore would work just fine.

Or for the case from my link above - If Comment class would have a Pointer to a Post class everything would work fine.

Aleksandar Ilic
  • 1,521
  • 16
  • 19
0

Have the same problem in parse 1.7.5 (release notes mentions that they fixed this bug, but still not working for me)

You can make it working with executing separate query for relation you have for each pinning object (maybe there is a way to do it with all objects at once?). And then pin results of relation query.

After that querying from local datastore starts working fine.

gleb vodovozov
  • 297
  • 3
  • 5