0

I'm using Restkit object mapping with the nested json data below. It will works great and each song object has a relevant rapper object. Except as you see below the rapper is the same for both songs, but each song object has a separate instance of a rapper object, so they don't match up when comparing. Is there a way to have Restkit use the same instances if they exist based on the unique id?

{
            "id": "1",
            "user_id": "200",
            "filename": "filename1.mp3",
            "mdate": "1250191261"
            "rapper": {
                "name": "Rap King",
                "id": "200"
            }
        },
        {
            "id": "2",
            "user_id": "200",
            "filename": "filename2.mp3",
            "mdate": "1345630910",
            "rapper": {
                "name": "Rap King",
                "id": "200"
            }
        }
Wasim
  • 4,953
  • 10
  • 52
  • 87

1 Answers1

1

If you are using a Core Data backed mapping you need to set primaryKeyAttribute=@"id" on your RKManagedObjectMapping.

Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
  • Thanks, but is there any way to do it without using CoreData? – Wasim Aug 23 '12 at 07:26
  • No, it can no longer build an object graph. But you can consider using an ["in-memory"](https://groups.google.com/forum/?fromgroups=#!topic/restkit/i1kWKu4kHBY) core data store by [modifying the store type](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSPersistentStoreCoordinator_Class/NSPersistentStoreCoordinator.html) – Paul de Lange Aug 23 '12 at 07:50