I have an ios 5 application that does not create any data - it just makes a GET call to the REST web service and populates the sqlite database with these records. The original GET works fine when there are no records in the local database. However, when I make subsequent calls, I will only return a subset of records whose data has changed since the last GET. But what happens is that the records are simply added again, rather than updating existing records.
I have an identifier field, which is the primary key (or should be), and when a record arrives whose identifier already exists, I want this data to be updated. If this identifier does not exist, it must be an insert.
I have not seen a way to set my ID field as a "primary key" in the datamodel in Xcode. I tried to do this in my didFinishLaunchingWIthOptions method:
userMapping.primaryKeyAttribute = @"id";
But this itself really did nothing.
This is my call to execute a GET:
// Load the object model via RestKit
[objectManager loadObjectsAtResourcePath:[@"/synchContacts" appendQueryParams:params] delegate:self];
Which seems to do everything automatically. I lost at this point about where I should put the logic in order to check if the identifier exists, and if so, is the insert or something updated.
source
share