views:

16

answers:

1

Hi,

I have two entities, A and B.

A has to-Many relation with B.

One B has always One A, but an A can be related to many B.

The SQL would be this, without joins for a better simplification:

SELECT a.id, a.name FROM a WHERE a.id IN (SELECT distinct(b.id_a) FROM b)

As I import those rows from an .xml file the first time, I can easly add a field in A and just update it if there are rows related from b. The fetched would be easy using this new field in the NSPredicate:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"has_b = %@",YES];

but I would like to know if this is really possible without too much extra work.

thanks,

m.

A: 

If your to-many relationship accessor is called my_bees, try:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"my_bees.@count > 0"];
Seamus Campbell
thanks, works perfectly!
mongeta