I am trying to execute a query on the context of a managed object with a predicate that checks the key path that exists in some subclasses of the abstract class.
For example, here is a part of the object model
Library::NSManagedObject - AllMovies::to-many relationship->Movie Movie::NSManagedObject (abstract) - type::String - name::String - mylibrary::to-one relationship->Library HorrorMovie::Movie - monster::String - ghosts::BOOL RomanceMovie::Movie - percociouskid::String - hasferret::BOOL
If I configured the following query to select
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Library" inManagedObjectContext:moc]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:entityDescription]; NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(SUBQUERY(AllMovies, $movies, $movies.type like[c] 'horror' and $movies.moster like[c] 'yeti' ) .@count != 0)" ] [request setPredicate:predicate]; NSArray *array = [moc executeFetchRequest:request error:&error];
Fetching a query returns an error, for example
keypath $movies.monster not found in entity <NSSQLEntity Movie id=2>
There doesn't seem to be a way to make a lazy predicate estimate. Some of the other things that I have already tried are ANY predicate using the CAST keyword, trying to replace the βAllMoviesβ in SUBQUERY with another SUBQUERY to return a group of objects that matches the type value.
It would be possible to fulfill several requests for each qualification type, but this is rude, slow and cumbersome.
This is under OS X 10.6 with persistent SQL storage. Running in a memory store is not an option since I work with 1 million + Libraries (the project really has nothing to do with movies, but I thought it was a good example).
Thanks Rob
source share