0

V <-->> O <<--> P

I am trying to write the right predicate so that I can get all V entities that have at least one or more O entities that match a certain P entity.

I've tried something like this:

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(O, $b, ANY $bs.P == %@).@count > 0", P];

Not working. Obviously I am not thinking about this correctly so far. Any idea how I can get this query done properly?

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
zumzum
  • 17,984
  • 26
  • 111
  • 172
  • You should see some useful stuff in the question and answers there. – jrturton Oct 06 '12 at 15:41
  • Thanks for the input. Still not sure how to write the predicate. I'll keep reading that question and answers to it you suggested in the meantime to see if I can figure it out. – zumzum Oct 07 '12 at 03:51

1 Answers1

2

Say the relationship in V to O is called os and the relationship from O to P is called p. The syntax for the subquery would be as follows:

   NSPredicate *predicate = [NSPredicate predicateWithFormat:
                              @"SUBQUERY(os, $o, $o.p == %@).@count != 0", pToMatch];
salo.dm
  • 2,317
  • 1
  • 15
  • 16