I have a database of People and pets, with a one to many relationship
Person Pet Name Name Pet <----->> Owner
I am using a UITableView backed by Core data and a nsfetchedresultscontroller to display the list of pets, grouped into sections by the owner.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [NSEntityDescription entityFromName:@"Pet"
inManagedObjectContext:context]
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Owner.name"
ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:@"Owner.name"
cacheName:@"Root"];
This works to display all pets under their owners section, however I also want to display the empty sections of People who do not have any pets? Is this possible?
Thanks for any help.