RKObjectLoader removes all coredata objects as orphans and replaces with identical new objects!

80 views
Skip to first unread message

Joe Kramer

unread,
Jun 2, 2012, 2:51:32 PM6/2/12
to res...@googlegroups.com

How do I make RestKit not delete but update existing objects? 

On every GET I receive same objects. But rest kit deleted existing objects and replaces them with identical copies.


Object mapping:


RKManagedObjectMapping* itemMapping = [RKManagedObjectMapping mappingForClass:[Item class] inManagedObjectStore:objectStore];

itemMapping.primaryKeyAttribute = @"itemId";

[itemMapping mapKeyPath:@"id" toAttribute:@"itemId"];


JSON response with id:

RKResponse.m:218 Read response body: [{"id":144614501} ......


estkit.core_data:RKManagedObjectLoader.m:143 Deleting orphaned object <Item: 0xc93ad60> (entity: Item; id: 0xc935c20 <x-coredata://03AD71D5-2841-434D-8482-E840B879EC20/Item/p478> ; data: {

    itemId = 144614501;



It's same primary key!!! Identical object! Why does it do that?

It looks like RestKit creates new objects first in

RKOBjectLoader - (RKObjectMappingResult*)mapResponseWithMappingProvider:(RKObjectMappingProvider*)mappingProvider toObject:(id)targetObject inContext:(RKObjectMappingProviderContext)context error:(NSError**)error;


And then there's comparison in
RKManagedObjectLoader: (void)deleteCachedObjectsMissingFromResult:(RKObjectMappingResult*)result


Basically it comes down to this:

for (id object in cachedObjects) {

            if (NO == [results containsObject:object]) {

                RKLogTrace(@"Deleting orphaned object %@: not found in result set and expected at this resource path", object);

                [[self.objectStore managedObjectContextForCurrentThread] deleteObject:object];

            }

        }


How can our existing CoreData object be in cachedObjects if cachedObjects was just created from received data?

Am I missing something? 



How do I make it not delete but update existing objects?

Thank you.

marx

unread,
Jul 4, 2012, 8:24:31 AM7/4/12
to res...@googlegroups.com
I have simmilar problem, is there any chance to update existing objects (and not delete them) ? If anybody solve that problem, please post the solution here.

ps. i`m using RestKit 0.9.0
Reply all
Reply to author
Forward
0 new messages