seemingly simple Core Data fetch question
seemingly simple Core Data fetch question
- Subject: seemingly simple Core Data fetch question
- From: Gonzalo Castro <email@hidden>
- Date: Tue, 28 Aug 2007 22:39:08 -0400
Hello,
I have a Department, an Employee, and a CompanyCar entity.
Department has a to-many relationship to Employee and Employee has a
to-one relationship to Department.
Employee has a to-one relationship to CompanyCar and CompanyCar has a
to-one relationship to Employee.
I want to perform a fetch that results in all employees within a
department who do not have a company car.
With the code below I can fetch the employees belonging to _any_
department who don't have a company car but I just want to limit the
fetch to employees within a specific department.
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName: @"Employee" inManagedObjectContext:
myManagedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity: entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(myCompanyCar == NIL)"];
[request setPredicate: predicate];
NSError *error = nil;
NSArray *fetchResult = [myManagedObjectContext executeFetchRequest:
request error: &error];
I think I have to change the predicate to something like
@"(myCompanyCar == NIL) AND department == <a specific department>".
however I'm not sure how to refer to a specific managed object in the
predicate. Or is there a better way to do this fetch?
Gonzalo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden