我有以下CoreData对象模型

现在,我在使用以下条件进行谓词时遇到了问题。
获取所有位于以下位置的DBOpportunity
DBOpportunity.stateCode == 1
和
DBOpportunity.invoiceDate >= GIVEN_DATE
和
DBOpportunityLines.crmAccept == 1或DBOpportunityLines.crmAccept == 3
我已经尝试了很多示例和apple的编程指南,但都不能做到这一点。
发布于 2013-05-24 15:18:15
您还可以获取opportunityLines,然后获取父实体,如下所示:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"opportunityLines" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSDate *yourDate = [NSDate date];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(crmAccept==1 OR crmaccept==3) AND opportunity.stateCode==1 AND opportunity.invoiceDate>=%@", yourDate];
[fetchRequest setPredicate:predicate];
NSError *error;
//So here you have your array of opportunitylines
NSArray *opportunityLines = [context executeFetchRequest:fetchRequest error:&error];
//And this is how you get your opportunity objects
NSArray *opportunities = [opportunityLines valueForKeyPath:@"@distinctUnionOfObjects.opportunity"];https://stackoverflow.com/questions/16728294
复制相似问题