Note that there are some explanatory texts on larger screens.

plurals
  1. PORestkit-loaded nested Core Data entities cause NSObjectInaccessibleException
    primarykey
    data
    text
    <p>I'm using RestKit to grab objects from my RoR service and using CoreData to persist some of the objects (more static-type lookup table objects). TasteTag is one of those persisted objects:</p> <pre><code>#ifdef RESTKIT_GENERATE_SEED_DB NSString *seedDatabaseName = nil; NSString *databaseName = RKDefaultSeedDatabaseFileName; #else NSString *seedDatabaseName = RKDefaultSeedDatabaseFileName; NSString *databaseName = @"Model.sqlite"; #endif RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:kServerURL]; manager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName usingSeedDatabaseName:seedDatabaseName managedObjectModel:nil delegate:self]; .. lots of fun object mapping .. RKManagedObjectMapping* tasteTagMapping = [RKManagedObjectMapping mappingForClass:[TasteTag class]]; [tasteTagMapping mapKeyPath:@"id" toAttribute:@"tasteTagID"]; [tasteTagMapping mapKeyPath:@"name" toAttribute:@"name"]; tasteTagMapping.primaryKeyAttribute = @"tasteTagID"; [[RKObjectManager sharedManager].mappingProvider setMapping:tasteTagMapping forKeyPath:@"taste_tags"]; [[RKObjectManager sharedManager].mappingProvider addObjectMapping:tasteTagMapping]; .. some more mapping .. </code></pre> <p>I have the data coming back from the RoR server and it's getting mapped to objects as expected. The Core Data entity also seems mapped fine after RestKit gets the request back:</p> <pre><code>"&lt;TasteTag: 0x6e87170&gt; (entity: TasteTag; id: 0x6e85d60 &lt;x-coredata://03E4A20A-21F2-4A2D-92B4-C4424893D559/TasteTag/p5&gt; ; data: &lt;fault&gt;)" </code></pre> <p>The issue is when I try to access properties on the objects the fault can't seem to be fire. At first I was just calling the properties, which always came back as nil (even though that should fire the fault):</p> <pre><code>for (TasteTag *tag in self.vintage.tasteTags) { [tagNames addObject:tag.name]; //get error of trying to add nil to array } </code></pre> <p>After looking into manually triggering faults (<a href="http://www.mlsite.net/blog/?p=518">http://www.mlsite.net/blog/?p=518</a>) I tried calling <code>[tag willAccessValueForKey:nil]</code> which results in:</p> <pre><code>Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x6e7b060 &lt;x-coredata://03E4A20A-21F2-4A2D-92B4-C4424893D559/TasteTag/p5&gt;'' </code></pre> <p>Looking up the entity in the .sqlite based on the key (TasteTag/p5) does show it mapped to the one I'd expect.</p> <p>Other posts relating to RestKit recommend disabling the object cache (which I'm not using) since this is usually caused by an entity being deleted. But at this stage I'm just reading, not deleting, and I have no cache in place.</p> <p>If I just call <code>[TasteTag allObjects]</code> I'm able to get all the objects back fine and they load without issue. It's just in the case when they are faulted it seems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload