0
votes

I am mapping with simple json response,

{
    "town": "ABC",
    "website": "http://xyz.com",
    "fee": "50.00",
    "event_id": 32,
    "images": [
        {
            "large": "1.jpg",
            "thumbnail": "2.jpg"
        },
        {
            "large": "1.jpg",
            "thumbnail": "2.jpg"
        },
        {
            "large": "1.jpg",
            "thumbnail": "2.jpg"
        }
    ]
}

and my mapping function look like this

RKManagedObjectMapping *eventMapping = [RKManagedObjectMapping mappingForClass:[Events class] inManagedObjectStore:manager.objectStore];
[eventMapping  mapKeyPath:@"town" toAttribute:@"town"];
[eventMapping  mapKeyPath:@"website" toAttribute:@"website"];
[eventMapping  mapKeyPath:@"fee" toAttribute:@"fee"];
[eventMapping  mapKeyPath:@"event_id" toAttribute:@"event_id"];
eventMapping.primaryKeyAttribute = @"event_id";
[manager.mappingProvider setMapping:eventsMapping forKeyPath:@""];

RKManagedObjectMapping *imagesMapping = [RKManagedObjectMapping mappingForClass:[Images class] inManagedObjectStore:manager.objectStore];
[imagesMapping  mapKeyPath:@"large" toAttribute:@"large"];
[imagesMapping  mapKeyPath:@"thumbnail" toAttribute:@"thumbnail"];

[eventsMapping mapKeyPath:@"images" toRelationship:@"images" withMapping:imagesMapping];

But i am not to make a relationship successfully. My Db is always showing empty relationship b/w images and events. i tried connectrelationship, but i think i need primary key for images table to make a connection. can anyone guide me to correct way of doing this.

Do i need to add primary key for Images table or is it possible to access the 'event_id' from parent table (event) and use it for making relations.

1
This is not related to Xcode, don't use the xcode tag. - user529758
And it's more iOS than iPhone - HAS
If you're new to RestKit, why are you using the old version ? - Wain
i thought it is not stable yet. that's why i switch to old version - iPhone Guy

1 Answers

0
votes

Try this

    //Note this is Restkit 0.2
    [eventMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"images" toKeyPath:@"images" withMapping: imagesMapping]];