NSPredicate and to-many relationships
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