1

I've found various ways including this to test for the existence of to many relationships. What I want to know though is how to test for the non-existence of a one way relationship. Here's what I've come up so far:

NSPredicate *p = [NSPredicate predicateWithFormat:@"category = nil AND (ANY %@ <= created_at) AND (ANY created_at <= %@)", date1, date2];

The previous code will raise this exception:

The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.

I'm not sure what's wrong here, I just want to fetch records with category nil.

Community
  • 1
  • 1
Oscar Del Ben
  • 4,485
  • 1
  • 27
  • 41

1 Answers1

3

First of all, I'd put the first expression in paranthesis too.

Secondly your exception has nothing to do with checking for a nil value, but (as the exception suggests) with putting ANY at the beginning of the other two expressions. You're checking for single dates in both cases, not arrays of dates. Just leave the ANY's out and it should be working as expected.

Just in case date1 and date2 are in fact arrays, you need to use the %K placeholder instead of %@ for dynamic objects.

Toastor
  • 8,980
  • 4
  • 50
  • 82