Sunday, 15 March 2015

ios - RestKit: Fetching parent objects from child object, having 2 foreign keys -



ios - RestKit: Fetching parent objects from child object, having 2 foreign keys -

i using restkit coredata , have 2 entities, mainitem , subitem 1 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 next 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: able fetch info coredata objects. don't know how set relationships between them, can refer parent-object's data.

by using next statement, able fetch 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 supposed display retailer info corresponding mainitem1 & mainitem2. problem is, don't know how fetch these values parent-object.

will relationsubtomainitem can made refer/return 2 parent objects?

ios core-data restkit foreign-key-relationship

No comments:

Post a Comment