How do I access the attribute of a one to many relationship and pass to another tableview?

38 views Asked by At

So I have two entities in CoreData (A and B). A has many Bs and B can only belong to one A. I have managed to display A on a tableview and when I tap a cell, it should segue to another tableview controller that displays the list of Bs. I am using NSFetchedResultsController to monitor my tableview. In my didSelectRowAtIndexPath method, I have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.tappedIndex = indexPath;
NSLog(@"Index tapped is %@",self.tappedIndex);
NSLog(@"%@",[self.fetchedManagedResultsController objectAtIndexPath:self.tappedIndex]   );

}

The output from the NSLog is:

<B: 0x1700b1a00> (entity: B; id: 0xd000000000500000 <x-coredata://5A01CF10-0E90-496F-9B84-FAF68346D6DC/Customer/p20> ; data: {
items = "<relationship fault: 0x174221ee0 'items'>";
name = "Connie  Brittani  ";
phone = 8034233759;

})

My question is how do I pass the items to the second tableview. Any help is appreciated!

1

There are 1 answers

0
jumpr3 On BEST ANSWER

So I read up more on faults and learned that it's actually not an error but more of a unrealized object. It will become a real object when it's called. In my case, I had a one-to-many relationship so entity B was a NSSet in the A.h file. I simply had to create a NSMutableSet and initialize it with the code above.