I have two entities. Employee
entity
@interface Employee : NSManagedObject
@property (nonatomic, retain) NSString * dept;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Department *deptEmp;
@end
and Department
entity
@interface Department : NSManagedObject
@property (nonatomic, retain) NSString * location;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Employee *deptEmp1;
I am trying to fetch information from both with following predicate
NSMutableString *queryString = [NSMutableString stringWithFormat:@"(name = 'Apple') AND (deptEmp1.location like 'Cupertino')"];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];
And Fetch Request is
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
[request setResultType:NSDictionaryResultType]; // NSFetchRequestResultType - NSDictionaryResultType
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Department",nil]];
[request setIncludesSubentities:YES];
Setting Predicate
if(![queryString isEqualToString:@""])
{
[request setPredicate:[NSPredicate predicateWithFormat:queryString]];
}
NSError *error = nil;
NSArray *returnArray = nil;
Fetching Result
@synchronized(self)
{
returnArray = [self.managedObjectContext executeFetchRequest:request error:&error];
}
But here I never get result.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…