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:-).
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)
The if-else will work because the university with the name will be in the context and can be easily fetched.