I have a Person class (attributes firstName and lastName) and another Worker object (payroll and title attributes). In my Core Data model, the Person object is defined as the parent Worker object. In my AppDelegate, I'm setting up my mapping ...
RKManagedObjectMapping* personMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Person" inManagedObjectStore:objectManager.objectStore]; [personMapping mapKeyPath:@"firstName" toAttribute:@"firstName"]; [personMapping mapKeyPath:@"lastName" toAttribute:@"lastName"]; [objectManager.mappingProvider addObjectMapping:personMapping]; RKManagedObjectMapping* workerMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Worker" inManagedObjectStore:objectManager.objectStore]; [workerMapping mapKeyPath:@"wage" toAttribute:@"wage"]; [workerMapping mapKeyPath:@"title" toAttribute:@"title"]; [objectManager.mappingProvider setMapping:workerMapping forKeyPath:@"workers"]; RKManagedObjectSeeder* seeder = [RKManagedObjectSeeder objectSeederWithObjectManager:objectManager]; [seeder seedObjectsFromFiles:@"people.json", nil];
... in people.json ...
{ "workers": [ { "firstName":"Rob", "lastName":"Johnson" }, { "firstName":"John", "lastName":"Roberts" } ] }
... now when I run this, the objects are not being seeded. How can I express the fact that the Worker class has the same mappings as Person? I could just add them to this comparison, but that seems wrong.
Also when registering Person mappings using ...
[objectManager.mappingProvider addObjectMapping:personMapping]
... I do not use the RKManagedObjectMapping setMapping: forKeyPath: method because we will never experience only Person in this application, and therefore we will never display it. But I still want him to register. for child objects of Person.
source share