NSPredicate filters data through relationships, not property

Here is my question. I have one model [Event] has several [Day], and in [Event] there is a relationship called days, and in [Day] there is a feedback event.

Now I want to pass an Event object and get all the days using NSFetchedResultsController, and load all the days in the table. Here is my code:

// Create the fetch request for the entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Day" inManagedObjectContext:managedObjectContext]; //set predicate -> ?? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"event = %@", self.currentEvent]; [fetchRequest setPredicate:predicate]; //set entity [fetchRequest setEntity:entity]; // Set the batch size to a suitable number. [fetchRequest setFetchBatchSize:20]; // Edit the sort key as appropriate. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; // Edit the section name key path and cache name if appropriate. // nil for section name key path means "no sections". NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil]; 

Somehow, an instance of NSFetchedResultsController will always return the same for another event. How do I fix NSPredicate?

+7
iphone core-data relationship nspredicate
source share
1 answer

I understood:

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", self.currentEvent.days]; 
+14
source share

All Articles