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 9095767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:41:17+00:00 2026-06-16T23:41:17+00:00

The Example: We have students and universities: student { id, name, university } university

  • 0

The Example:
We have students and universities:

student {
  id,
  name,
  university
}



university {
      id,
      name
}

And now consider the following json-object as a response from a server, which should be modeled using RestKit:

{
  "students": [{
    "id" : 1,
    "name" : "bob",
    "university":{
        "id" : 1,
        "name" = "blub-university" } 
  },
  {
    "id" : 2,
    "name" : "anton",
    "university":{ 
          "id" : 1 }
  }
  ]
}

Since the content for the university to id=1 is already known for anton, just the id is passed.

My problem:
I used a relationship between student and university in RestKit, but
Restkit overrides the university object when processing the response. What is the correct way to handle such responses?

I think this is a Bug in Restkit. I think it first creates the objects: bob and anton, but also two objects for the university.
Then it links these objects, but that does not work, because it created two university objects!

UPDATE:
My theory was wrong, I added outputs to the weskit-API, when objects are created.

My mistake:
I DID NOT SET THE PLURAL ATTRIBUTE OF THE RELATIONSHIPS ACCORDING TO THE JSON SYNTAX. RESTKIT WORKS FINE, but maybe some assertions in rest kit would be fine, to prevent this problem:-).

  • 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-16T23:41:18+00:00Added an answer on June 16, 2026 at 11:41 pm

    Assuming that is the response you receive and you are guaranteed to have the university with name return before one without, I would handle it like this.

    (Semi pseudo code)

    for(NSDictionary *dict in JSON){
        Student *stu = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:context];
        [stu set_Id:[dict objectForId:@"id"]];
        [stu set_Name:[dict objectForId:@"name"]];
        NSDictionary *uniDictionary = [dict objectForId:@"university"];
        University *uni = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:context];
        [uni set_Id:[uniDictionary objectId:@"id"]];
        if (uniDictionary objectForKey:@"name"] != nil) {
            [uni set_Id:[uniDictionary objectId:@"name"]];
        }
        else {
            NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"University"];
            fetchRequest.predicate = [NSPredicate predicateWithFormat:@"id == %d", [uniDictionary objectId:@"id"]];
            NSError *error;
            NSArray *arr = [context executeFetchRequest:fetchRequest error:&error];
            University *uniWithName = arr[0];
            [uni set_Name:uniWithName.name];
        }
    }
    

    The if-else will work because the university with the name will be in the context and can be easily fetched.

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

Sidebar

Related Questions

Example: I have an class that inherits from UIImageView. An object creates an instance
So I have these tables: STUDENTS: Student ID - First name - Last name
Here's the problem. I ,for example,have a string 2500.Its converted from byte array into
I have defined a custom object with multiple fields. For example say I have
I have a single table that houses student scores by their classes. For example,
Suppose I have the following function: ## Just an example f = function() {
Okay, so here's an example scenario. There is a student resource resources :students ,
I have , for example, two entities called Class and Student . Both entities
For example: I have a database of students and last classes, and for each
I have grades for students and levels of proficiency. for example, for 5th grade,

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.