I know Core Data is not a database and there are many differences. Is this one?
In a database, I would commonly have the following
A ->> B ->> C
"A" has many "B" which has many "C"
The query, "Give me all A's which have c.attr = 'X' is easily written like:
select * from a, b, c where a.id = b.aid and b.id = c.bid and c.attr = 'X'
In Core Data, I would like to do the same, but using a predicate like:
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"ANY bs.cs.attr = %@", "X"];
[frequest setEntity:entityA];
[frequest setPredicate:predicate];
Doing this results in the error: 'NSInvalidArgumentException', reason: 'multiple to-many keys not allowed here'
Am I correct to interpret to mean there is a limitation on what databases call multi-table joins?
I googled around and couldn't find a definitive answer.
My current solution to this query looks like:
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"ANY cs.attr = %@", "X"];
...
NSArray *bs = //execute fetch
for (B *b in bs) {
//add b.a into an array
}
//return array
Is there a better way? Thanks in advance for the consideration.