Re: CoreData, NSPredicate, searching for object with a specific number objects of relationships
Re: CoreData, NSPredicate, searching for object with a specific number objects of relationships
- Subject: Re: CoreData, NSPredicate, searching for object with a specific number objects of relationships
- From: Conor <email@hidden>
- Date: Wed, 18 Apr 2007 19:25:05 +0200
>Is this possible with to-many-relationships (e.g. find all
>departments that have no employees)?
My knowledge is quite limited, but in lack of a wiser answer I would try:
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Department" inManagedObjectContext:managedObjectContext];
NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"count(
employees) == 0"];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity: entity];
[fetch setPredicate: predicate];
NSError *fetchError = nil;
NSArray *fetchResuls = [managedObjectContext executeFetchRequest:fetch
error:&fetchError];
if (fetchResuls == nil) {
NSLog(@"Fetch Error: %@ reason: %@ with: %@", [fetchError
localizedDescription], [fetchError localizedFailureReason], fetch);
}
[fetch release];
NSLog(@"fetch Results: %@", fetchResuls);
Regards,
Conor
http://www.bruji.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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