• 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
NSPredicate and to-many relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPredicate and to-many relationships


  • Subject: NSPredicate and to-many relationships
  • From: Kevin <email@hidden>
  • Date: Sat, 13 Jan 2007 06:06:07 -0600

I have an Entity called "Group" which has an inverse 1-to-many relationship with an entity called "Record".

I want to create a fetch request which returns all Groups that have Records whose titles contains a specific string. So, I did the following:

NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *groupEntity = [NSEntityDescription entityForName:@"Group" inManagedObjectContext:context];


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY records.title contains[c] 'somestring'"];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:groupEntity];
[fetch setPredicate:predicate];


NSError *error = nil;
NSArray *results = [context executeFetchRequest:fetch error:&error];
NSLog( @"results count: %d", [results count] );

When I run the above code, the following message is logged to the console:

The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.

If I change the predicate to @"ANY records.title like[c] '*somestring*'", it works. I'd prefer to use "contains" as the title may contain newlines.

Has anyone run across this problem?

Kevin
_______________________________________________

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


  • Follow-Ups:
    • Re: NSPredicate and to-many relationships
      • From: mmalc crawford <email@hidden>
    • Re: NSPredicate and to-many relationships
      • From: Timothy Larkin <email@hidden>
  • Prev by Date: Re: Illegal NSTableView data source
  • Next by Date: [Announce] First meeting of Montreal dev user group
  • Previous by thread: Re: NOT solved: using long double math functions like sinl() with Cocoa
  • Next by thread: Re: NSPredicate and to-many relationships
  • Index(es):
    • Date
    • Thread