0

I have a one to many relationship between Games and Players. There is a relationship on Games to Players called players.

Games <-->> Players

The Games entity has a relationship called players. Players has an attributed named 'order'

I am unable to use a predicate to query on the relationship. Here is the code I am using:

    -(NSArray *)returnPlayerLastAtBat: (int)rosterNo
    {
        NSError *error;

        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription 
                                       entityForName:@"Games" inManagedObjectContext:managedObjectContext];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:
                                  @"(finished = '%d') and (players.order = '%d')",0,rosterNo];
        [fetchRequest setEntity:entity];
        [fetchRequest setPredicate:predicate];

        NSArray* result = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
        [fetchRequest release];

return result;
}

Not sure what I am doing wrong- I am able to work with predicated throughout my project- but this one has been stuck.

Mike Jones
  • 65
  • 1
  • 7

1 Answers1

0

Take a look at this SO question. And as the mvds mentionned, remove the quotes around the %d.

Community
  • 1
  • 1
MGA
  • 3,711
  • 1
  • 21
  • 22
  • Thanks, Mattieu. This code worked for me: NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(finished = '%d') and (ANY players.order = '%d')",0,rosterNo]; – Mike Jones Feb 17 '12 at 00:52