我的程序有一个带有两个相关表的 sqlite 数据库。一个叫“等级”,一个叫“要求”
我想从“需求”表中获取与“等级”表中的特定行有关系的所有行。以下是我的代码,它抓取整个表,但我只根据上述规则获取指定的行。
-(NSArray *) getAllRequirementsForTheRank:(Rank *) rank
{
NSError *error;
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init]autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Requirement" inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
NSPredicate *searchType = [NSPredicate predicateWithFormat:@"Rank = %@", rank];
[fetchRequest setPredicate:searchType];
NSArray *scoutRequirementArray = [self.context executeFetchRequest:fetchRequest error:&error];
for (Requirement *r in scoutRequirementArray)
{
NSLog(@"Requirementttt : %@ :", r.requirementName);
}
return scoutRequirementArray;
}