Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit not deleting orphaned objects from local store
    primarykey
    data
    text
    <p>Hi i have updated RestKit from 0.10.2 to 0.20.3. After updating now when objects are missing from web service, RestKit not deleting them from local storage. I know it is supported in RestKit 0.20.x, but i am not being able to configure it. I followed the example given here. <a href="http://restkit.org/api/latest/Classes/RKManagedObjectRequestOperation.html#overview" rel="noreferrer">http://restkit.org/api/latest/Classes/RKManagedObjectRequestOperation.html#overview</a></p> <p>I also followed similar questions on Stackoverflow. But there is no accepted answer yet.</p> <p>Here is my Json</p> <pre><code>{ "status": "Success", "member_info": [ { "family_id": "1", "user_id": "1" }, { "family_id": "2", "user_id": "1" }, { "family_id": "3", "user_id": "1" } ] } </code></pre> <p>Which returns all Family members for a particular user. Above Json is for <code>user_id = 1</code>. Now i want if request is sent for <code>user_id = 2</code>, then all the previous 3 objects should be deleted from local storage, as they are now missing from Json. Here is the new Json for <code>user_id = 2</code></p> <pre><code>{ "status": "Success", "member_info": [ { "family_id": "4", "user_id": "2" }, { "family_id": "5", "user_id": "2" } ] } </code></pre> <p>This is how i am creating mapping.</p> <pre><code>[objectManager addResponseDescriptorsFromArray:@[ [RKResponseDescriptor responseDescriptorWithMapping:[self connectionsMapping] method:RKRequestMethodPOST pathPattern:@"familylist" keyPath:@"member_info" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]]; [objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) { RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"familylist"]; NSDictionary *argsDict = nil; BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&amp;argsDict]; if (match) { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"DBConnections"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id == %@", [DBUser currentUser].user_id]; fetchRequest.predicate = predicate; fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"first_name" ascending:YES] ]; return fetchRequest; } return nil; }]; - (RKEntityMapping *)connectionsMapping { RKEntityMapping *connectionsMapping = [RKEntityMapping mappingForEntityForName:@"DBConnections" inManagedObjectStore:objectManager.managedObjectStore]; connectionsMapping.setDefaultValueForMissingAttributes = NO; connectionsMapping.identificationAttributes = @[@"family_id"]; [connectionsMapping addAttributeMappingsFromDictionary:@{ @"family_id": @"family_id", @"user_id": @"user_id", }]; return connectionsMapping; } </code></pre> <p>In predicate i am using <code>[DBUser currentUser].user_id</code>, which returns the current logged in <code>user_id</code>. And here is i am calling the web service</p> <pre><code>[[RKObjectManager sharedManager] postObject:nil path:@"familylist" parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { NSLog(@"Objects are %@", mappingResult.array); }]; </code></pre> <p>I am using <code>postObject</code> instead of <code>getObjectsAtPath</code>, because server is expecting <code>POST</code> request method. Am i doing wrong? or need to do something else for deleting orphan objects. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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