0

现在,我的程序中的 setupFetchedResultsController 返回所有“食物”类型的实体,但我只想要“食物”类型的实体,它们也由我当前显示的“列表”实体持有。

holdBy 定义了“Food”和“List”之间的关系

有没有办法做到这一点?

我的 setupFetchedResultsController

- (void)setupFetchedResultsController
{
    // 1 - Decide what Entity you want
    NSString *entityName = @"Food"; // Put your entity name here
    NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);

    // 2 - Request that Entity
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];

    // 3 - Filter it if you want
    //request.predicate = [NSPredicate predicateWithFormat:@"Role.name = Blah"];

    // 4 - Sort it if you want
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
                      ascending:YES
                      selector:@selector(localizedCaseInsensitiveCompare:)]];
    // 5 - Fetch it
    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                      managedObjectContext:self.managedObjectContext
                      sectionNameKeyPath:nil
                      cacheName:nil];
    [self performFetch];
}
4

1 回答 1

0

我认为您可以使用您注释掉的谓词。

request.predicate = [NSPredicate predicateWithFormat:@"heldBy.name = name_of_list"];
于 2012-08-21T05:41:38.637 回答