1

I am using restkit with coredata and I have 2 entities, MainItem and SubItem with one to many relationship.

MainItem

   NSString * MainItem_Id  **(Primary Key)**;

   NSString *Name;

   NSString *Country;

   NSString * Retailer;

   NSSet * relationMainToSubItem;

SubItem

   NSString *SubItem_Id (Primary Key);

   NSString *Main_Item1 (Foreign Key);

   NSString *Main_Item2 (Foreign Key);

   NSString *Value;

   NSString *Link;

   NSSet *relationSubToMainItem;

My JSON objects have the following structure:

Main-Item JSON object:

MainItems:
{
    13950:
    {
        MainItem_Id:"13950",
        name:"Item Name1",
        country:"US",
        retailer: "",
    },
    13951:
    {
        MainItem_Id:"13951",
        name:"Item Name2",
        country:"FR",
        retailer: "",
    }
}

SubItem JSON Object

SubItems:
{
    14024:
    {
        SubItem_id: "14024",
        MainItem1_Id: "13950",
        MainItem2_Id: "13951",
        Value: "80",
        Link: "url1"
    },
    14025:
    {
        SubItem_id: "14025",
        MainItem1_Id: "13951",
        MainItem2_Id: "13956",
        Value: "90",
        Link: "url2"
    }
}

Question: I am able to fetch this data into coreData objects. I don't know how to set the relationships between them, so that I can refer to the parent-object's data.

By using the following statement, I am able to fetch the data.

[[RKObjectManager sharedManager] getObjectsAtPath:@”http://../subItem/read” parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    self.results = mappingResult.array; 
    [self.tableView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
//      
}];

I am supposed to display the retailer information corresponding to MainItem1 & MainItem2. My problem is, I don't know how to fetch these values from their parent-object.

Will the relationSubToMainItem can be made to refer/return 2 parent objects?

chit
  • 23
  • 5
  • Have you looked at http://stackoverflow.com/questions/17326087/foreign-key-relationship-mapping-with-restkit ? – Wain Oct 31 '14 at 15:25

0 Answers0