Core Data - NSPredicate on To-Many Relationship
I have 2 entities. Athlete(evals) <-->> Eval(whosEval). Athletes are
displayed in a table view and when one is selected, it takes you to a
tableview controller with all Evals. Unfortunately, I just want the Evals
for THAT Athlete. When I add an Eval, since I came from the Athlete
tableview, I pushed the information and set the whosEval as
currentAthlete. Can someone push me in the right direction with
NSPredicate and how to only retrieve Evals for Athletes with a certain
name?
addEval.h
AppDelegate *appDelegate = [[UIApplication sharedApplication]
delegate];
_managedObjectContext = [appDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Athlete"
inManagedObjectContext:_managedObjectContext]];
NSError *error = nil;
NSArray *results = [_managedObjectContext
executeFetchRequest:request error:&error];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"full
== %@", _whichAthletesEval];
[request setPredicate:predicate];
Athlete *currentAthlete = [results objectAtIndex:0];
[eval setWhosEval:currentAthlete];
}
NSError *error = nil;
if(![_managedObjectContext save:&error]){
//handle dat error
}
[self.navigationController popViewControllerAnimated:YES];
}
No comments:
Post a Comment