KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Can RestKit connect a relationship without storing the foreign key as an attribute, i.e., directly from the keypath in the JSON? In particular, I've got a Job has_many Rooms relationship. The room's JSON doesn't contain the job, rather, both are loaded separately: - job: { id: 1, name: "John" } - room: { id: 4, job_id: 1, name: "spare bedroom" } The Job is loaded before the Room. My CoreData models, Job has properties for @interface Job : NSManagedObject @property (nonatomic, retain) NSNumber * identifier; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSSet *rooms; @end @interface Room : NSManagedObject @property (nonatomic, retain) NSNumber * identifier; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) Job *job; @end Currently I add a @property (nonatomic, strong) NSNumber *jobID; to Room, which I @synthesize . JobMapping: mapping = [RKManagedObjectMapping mappingForClass:[Job class]]; [mapping setPrimaryKeyAttribute:@"identifier"]; [mapping mapAttributes:@"name", nil]; [mapping mapKeyPath:@"id" toAttribute:@"identifier"]; [mapping mapRelationship:@"rooms" withMapping:[Room objectMapping]]; RoomMapping mapping = [RKManagedObjectMapping mappingForClass:[Room class]]; [mapping setPrimaryKeyAttribute:@"identifier"]; [mapping mapAttributes:@"name", nil]; [mapping mapKeyPath:@"id" toAttribute:@"identifier"]; [mapping mapKeyPath:@"job_id" toAttribute:@"jobID"]; [mapping mapRelationship:@"job" withMapping:[Job objectMapping]]; [mapping connectRelationship:@"job" withObjectForPrimaryKeyAttribute:@"jobID"]; I was wondering if there's a way I can do this without the extra jobID property? I don't want to have a jobID attribute in the CoreData xcdatamodeld - it's redundant, as th
Tags (comma-separated)
Save Edits
Cancel