I am using restkit. My coredata entities are arranged as shown in the screeshot
I have added following fetch request block to delete orphaned objects
[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/api/lists/:phone_no"];
NSDictionary *argsDict = nil;
BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
NSString *phone_no;
if (match)
{
phone_no = [argsDict objectForKey:@"phone_no"];
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"List"];
//we don't need request predicate here. We delete all local items which are not present in retruned response.
return fetchRequest;
}
return nil;
}];
It works fine for orphaned List and Task objects. For example if a task of some list gets deleted over the server, then on refreshing it also disappears form local store and hence the table-view.
But child of Task like 'Task Log', 'Task Comment' and 'Task Note' don't get deleted form local store if their server counterparts are deleted.
For example if task note of task is deleted from sever then on refreshing data the 'now' orphaned task comment still shows in the table.
I am using this GET Descriptor which returns all the relevant data in appropriate JSON Format
//Response Descriptor GET for List
RKResponseDescriptor *listResponseDescriptorGET = [RKResponseDescriptor responseDescriptorWithMapping:listEntityMapping
method:RKRequestMethodGET
pathPattern:@"/api/lists/:phone_no"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
What i am doing wrong? I use fetch results controllers everywhere which automatically updates views.
I can provide more information if required.