Core Data: Need help with fetch request
Core Data: Need help with fetch request
- Subject: Core Data: Need help with fetch request
- From: Diederik Hoogenboom <email@hidden>
- Date: Tue, 10 Oct 2006 21:27:37 +0200
I want to fetch some objects based on a condition existing in one of
its relationships.
Example Object Model:
Car -> Wheel
A car can have one or more wheels. And a wheel has a property called
color (to keep it simple an NSString). The relationship is called
wheels. There is no inverse relationship.
What I want is to retrieve all cars that a color that contains the
word 'black'.
Code I've tried so far:
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Car" inManagedObjectContext:context];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString
stringWithFormat:@"ANY wheels.color like '*black*'] ];
[request setPredicate:predicate];
NSArray *array = [context executeFetchRequest:request error:nil];
Unfortunately the fetch request does result in any objects retrieved.
I am using an SQL-lite store for this example.
Kind regards,
Diederik
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden