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\" h
Is it possible for core data to add tests for attributes of both b and a? Or will I have to iterate over each result set successively to get my final result?
select
p.id, p.total
from
purcord p, line l, delivery d
where
l.purcord_id = p.id
and d.purcord_id = l.purcord_id
and d.purcord_line_no = l.line_no
and d.status = 'notdelivered'
and l.status = 'open'
and p.status = 'open'
Your going about this backwards.
First of all, you don't need the linking ids in Core Data because all related objects are already linked by the relationship. This means constructions like where a.id = b.aid and b.id = c.bid
aren't needed at all.
Secondly, you generally set the fetch entity for the entity that receives the defining test. In this case, that is c.attr="X"
So, you set your fetch entity to C
and your predicate should look something like:
NSPredicate *p=[NSPredicate predicateWithFormat:@"attr=%@",xValue];
This will return an array all the C
instances that meet the test. Then finding any particular B
or A
is just a matter of walking the relationship for each C
.
If your inverse relationship is to-one e.g A<->>B<->>C, the you just ask each C
for the value of the b.a
so:
AObject *anA = aCinstance.b.a;
It's important to remember you are not dealing with tables here. You are dealing with an object graph. You set the fetch to a particular entity and then walk the filtered entities' relationships.