My setup
The following all works fine:
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"];
I can call
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/channels" delegate:self];
and I get my channel's from the server and they're stored locally by Core Data. Perfect.
The issue
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:
[objectManager.mappingProvider setObjectMapping:chanMapping forResourcePathPattern:@"/channels" withFetchRequestBlock:^ (NSString *resourcePath) {
return [Channel fetchRequest];
}];
However with this all the Channels get deleted whenever there is anything new on the server.
Things I've tried [UPDATED]
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).
In deleteCachedObjectsMissingFromResult
the cachedObjects
array looks good, has all the objects that should be there from the last time but the results
array is empty which obviously results in [results containsObject:object]
always being NO
and all the objects being deleted.
Do I need to change something to do with the resource path mapping?