Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchResultController - one-many relationship
    text
    copied!<p>i have four tables. This is my table structure</p> <p>Master >---->> Projects >---->> Tasks >----> Document</p> <p>I am using NSFetchResultController to fetch objects from Database. Tasks are loaded in the tableview based on number of tasks for the projects. (for now there is only one project)</p> <p>i can use following code to get the task objects</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tasks" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"taskId" ascending:NO]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]]; [fetchRequest setFetchBatchSize:20]; NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:@"Root"]; self.fetchedResultsController = theFetchedResultsController; _fetchedResultsController.delegate = self; </code></pre> <p>which returns the number of Tasks and i can use like this.</p> <pre><code>id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section]; </code></pre> <p>But i need to use from top level objects like Master -- >> Projects -->> Tasks. How can i implement top level objects instead of using "Tasks" in FetchResultController.</p> <p>i.e,</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Master" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; </code></pre> <p>I don't have any id in master to sort. Master has one - many relationship with Projects. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload