Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit Object Mapping: difficulty using setObjectMapping:forResourcePathPattern:withFetchRequestBlock
    text
    copied!<p><strong>My setup</strong></p> <p>The following all works fine:</p> <pre><code>RKManagedObjectMapping* chanMapping = [RKManagedObjectMapping mappingForClass:[Channel class] inManagedObjectStore:objectStore]; chanMapping.primaryKeyAttribute = @"chanId"; [chanMapping mapKeyPathsToAttributes: @"id",@"chanId", @"name", @"chanName", nil]; [objectManager.mappingProvider setMapping:chanMapping forKeyPath:@"Channels.channel"]; </code></pre> <p>I can call</p> <pre><code>[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/channels" delegate:self]; </code></pre> <p>and I get my channel's from the server and they're stored locally by Core Data. Perfect.</p> <p><strong>The issue</strong></p> <p>However, I now wan't to have RestKit automatically delete Channels from the Core Data store that have been removed from the server the next time a GET is performed. I understand this is supported by adding the following:</p> <pre><code>[objectManager.mappingProvider setObjectMapping:chanMapping forResourcePathPattern:@"/channels" withFetchRequestBlock:^ (NSString *resourcePath) { return [Channel fetchRequest]; }]; </code></pre> <p>However with this all the Channels get deleted whenever there is anything new on the server.</p> <p><strong>Things I've tried</strong> [UPDATED]</p> <p>I've debugged using the steps in the answer below. It looks as though the mapping isn't working / is not being found (i.e. I haven't properly associated the mapping with the resource path).</p> <p>In <code>deleteCachedObjectsMissingFromResult</code> the <code>cachedObjects</code> array looks good, has all the objects that should be there from the last time but the <code>results</code> array is empty which obviously results in <code>[results containsObject:object]</code> always being <code>NO</code> and all the objects being deleted.</p> <p>Do I need to change something to do with the resource path mapping?</p>
 

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