12

I have a query with many includeKeys which are pointers to another class. After receiving the data from parse cloud all the records are getting stored locally using pinAll method. When I fetch back the results stored, I can able to get the records but not pointers included. See sample code below

[query includeKey:@"classOne.innerClass"];
[query includeKey:@"classTwo.innerClass"];
[query includeKey:@"classThree"];
[query includeKey:@"classFour"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
   [PFObject pinAllInBackground:objects withName:@"LocalRecords" block:^(BOOL succeeded, NSError *error) {

   }];
}];

And I am fetching the records like

PFQuery *lquery = [PFQuery queryWithClassName:[ClassName parseClassName]];
   [lquery fromPinWithName:@"LocalRecords"];
   BFTask *btask = [[lquery findObjectsInBackground] continueWithSuccessBlock:^id(BFTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error);
            return task;
        }
   }];

When I try to access any of the columns in classOne, classTwo, classThree and classFour I am getting an exception Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "name" has no data. Call fetchIfNeeded before getting its value.'

Ryan Kreager
  • 3,571
  • 1
  • 20
  • 35
san
  • 295
  • 2
  • 18
  • Before you can fetch from the local database, you have to tell the query where it needs to look `[query fromLocalDatastore];` – jsetting32 Dec 21 '14 at 05:56
  • I am already using this..... No luck – san Dec 22 '14 at 09:24
  • I'm interested to know more about this issue as well. What version of the iOS SDK did you test this against? – fatuhoku Jan 19 '15 at 15:42
  • And what's your milage with http://stackoverflow.com/a/27586395/590767? – fatuhoku Jan 19 '15 at 15:43
  • @fatuhoku I am working with the latest environment. xcode 6 with iOS8. – san Jan 23 '15 at 14:12
  • and this issue is fixed with the latest parse SDK(v1.6.1). – san Jan 23 '15 at 14:21
  • @san, I am not able to fetch using v1.6.2. When I include any key then it gives me 0 objects else gives all. Seems not fixed even in recent version. – Shiva Reddy Feb 19 '15 at 11:54
  • @ShivaReddy, You are right. There is an active thread about this issue [here](https://developers.facebook.com/bugs/1771368209755734/) – san Feb 19 '15 at 12:04
  • Actual issue is different from this. Calling includKey for the local query(**lquery**) solves the above issue. – san Feb 19 '15 at 12:11
  • I did [lquery includeKey:@"category"]; but when I do this not able fetch any objects the count is 0, but if I remove and and make a query getting all (26 currently stored) objects but without pointers. – Shiva Reddy Feb 19 '15 at 12:24
  • Ensure that you don't have any dangling pointers in your class(which you are including). – san Feb 19 '15 at 12:51

1 Answers1

1

This was a bug in the Parse.com local data store functionality for iOS.

From the 1.6.3 release notes:

"Improved consistency of Local Datastore / Parse queries with includeKey: and NSNull values."

Ryan Kreager
  • 3,571
  • 1
  • 20
  • 35