• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData, NSPredicate, searching for object with a specific number objects of relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: What's the "Objective-C garbage Collection"?
  • Next by Date: Re: About NSEnumerator
  • Previous by thread: Re: What's the "Objective-C garbage Collection"?
  • Next by thread: Inserting localized text to NSTextView
  • Index(es):
    • Date
    • Thread