Request with CoreData

Here is my problem :

My CoreData model have two entity : Players and Results. The important properties of Players are : - ratingTypePlayer, which is a String. - resultsPlayer which is a Too-Many Relationship with Results as Destination. The Inverse relationship is playerResult.

I wish to obtain an array with all the Results of the Players which ratingTypePlayer is equal to "Toto". I don't find this kind of example.

Thanks a lot

Upvotes: 0

Views: 80

Answers (1)

Francis McGrew
Francis McGrew

Reputation: 7272

You mean, like a fetch request?

NSManagedObjectContext *context = [[NSApp delegate] managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Player" inManagedObjectContext:context]];
[request setPredicate:[NSPredicate predicateWithFormat:@"ratingTypePlayer == %@", @"Toto"]];
NSArray *players = [context executeFetchRequest:request error:nil];

If you wanted an array of the "resultsPlayer" relationships, you could do:

NSArray *results = [players valueForKey:@"resultsPlayer"];

Upvotes: 1

Related Questions