Hi all,
I'm trying to execute a fetch request against a Managed Object Context with a predicate that tests against a keypath that exists in some subclasses of an 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 set up the following fetch request
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];
Executing the fetch request returns an error like
keypath $movies.monster not found in entity <NSSQLEntity Movie id=2>
It doesn't seem like there is a way to do lazy evaluation of the predicate. Some of the other things I've already tried are an ANY predicate, using the CAST keyword, trying to replace 'AllMovies' in the SUBQUERY with another SUBQUERY to return a group of objects that matches the 'type' value.
It would be possible to do multiple requests for each qualifying type, but that is gross, slow and unwieldy.
This is under OS X 10.6 with an SQL persistent store. Doing an in memory store is not an option since I'm working with 1 million+ 'Libraries' (the project doesn't really have anything to do with movies but I thought it was a good example).
Thanks, Rob