Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:41:53+00:00 2026-06-03T07:41:53+00:00

Can RestKit connect a relationship without storing the foreign key as an attribute, i.e.,

  • 0

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 the relationship covers that.

Also if I rebuild the NSManagedObjects, I need to re-add the jobID property, which is tedious. Can’t I tell restkit to connect the Room to its corresponding Job via the job_id keypath in the JSON?

If I remove the property, the mapKeyPath:@"job_id" line, and change the last line to [mapping connectRelationship:@"job" withObjectForPrimaryKeyAttribute:@"job_id"]; I get

the entity Room is not key value coding-compliant for the key "job_id".
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:41:54+00:00Added an answer on June 3, 2026 at 7:41 am

    I would make JobId a transient value in core data, and write a custom set and get for it.

    The set would set the relationship to self.job=methodToReturnObjectMatchingJobId (this would be used by rest kit)

    The get would return self.job.identifier

    If you are not using mogenerator, I would suggest you have a look at it for all your core data needs.

    Below is sample code of how i did it:

    -(void) setClaimId:(NSNumber *)claimId{
         Claim *propertyClaim=[Claim listItemFromId:[claimId intValue] withContext:self.managedObjectContext]; 
    
        self.claim=propertyClaim; 
    }
    -(NSNumber*) claimId{
    
      return self.claim.referenceId;
    }
    

    where listItemFromId is a simple query that returns the object based on the id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm unsingf RestKit in my iPad Project pulling some JSON Data from Server. The
How can I map the nested json below with RestKit RKObjectMapping? I only need
I'm trying to use JSON parsing from RestKit, but I'm receiving the following compile
I'm using the RestKit iOS package to allow a user to pull info from
I'm using RestKit to grab objects from my RoR service and using CoreData to
On iOS 5, how can I query a web service using a JSON object?
Can anyone give me an example of how to return the following json simply
I use RestKit with Object-mapping. This runs asyncronus and after receiving the Data from
I am using RestKit, GData and Facebook API. All of them has a JSON
Is it possible to deserialize an NSString of JSON into objects via RestKit? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.