I need to load mulitple objects that don't have relationships but located on the same remote API using RestKit into CoreData (in other words download remote objects to use them locally in iOS)
So I've setup my Client and objectManager:
client = [RKClient clientWithBaseURL:[NSURL URLWithString:baseUrl]];
[client setUsername:@"someUsername"];
[client setPassword:@"somePassword"];
objectManager = [RKObjectManager managerWithBaseURLString:baseUrl];
[objectManager setClient:client];
Then I setup some mappings for one Object#1:
RKManagedObjectMapping* companyMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Company" inManagedObjectStore:objectManager.objectStore];
companyMapping.primaryKeyAttribute = @"backendID";
[companyMapping mapKeyPath:@"id" toAttribute:@"backendID"];
[companyMapping mapKeyPath:@"company_name" toAttribute:@"companyName"];
Then I setup some mappings for Object #2:
RKManagedObjectMapping* eventMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Event" inManagedObjectStore:objectManager.objectStore];
eventMapping.primaryKeyAttribute = @"backendID";
[eventMapping mapKeyPath:@"id" toAttribute:@"backendID"];
[eventMapping mapKeyPath:@"description" toAttribute:@"eventDescription"];
After that I set objectMapping to mappingProvider:
[objectManager.mappingProvider setObjectMapping:companyMapping forResourcePathPattern:remoteObjectPath];
[objectManager.mappingProvider setObjectMapping:eventMapping forResourcePathPattern:remoteObjectPath];
And lastly I call "loadObjects..." for both of these objects one after another:
[objectManager loadObjectsAtResourcePath:remoteCompaniesObjectPath delegate:self];
[objectManager loadObjectsAtResourcePath:remoteEventsObjectPath delegate:self];
What happens after this that data from both Companies and Events is somehow loaded into the Events table, so table data is completely unusable.
If I run only loadObjectsAtResourcePath:remoteCompaniesObjectPath then everything works as expected remote Company object downloads into it's own table in the CoreData.
While it does make sense why it's happening (data For Companies starting to load and gets new mapping, so it loads to the wrong table) the QUESTION is:
How to call loadObjectsAtResourcePath:remoteObjectPath methods to load multiple unrelated objects so they would properly loaded into their respective tables in the CoreData???