views:

371

answers:

2

I have a to-many relationship in my data model, and I'd like to get all the objects that have no corresponding objects in the relationship. For example:

Customer -> Purchases

I want to get all Customers that have 0 Purchases.

I've read somewhere that I could use "Purchases[SIZE] = 0", but this gives me an unsupported function expression error, which I think means it doesn't work with a SQLite backing store (which I don't want to switch from, due to some performance constraints).

Any ideas?

+3  A: 

I found the answer elsewhere, here it is for future use. Tested on iPhone OS 3.0.

[NSPredicate predicateWithFormat:@"Purchases.@count == 0"];

rwat
The "@count" function seems to work on Snow Leopard but **does not work** on Leopard. I got `undefined to-many relationship keypath` exception. Any solutions? Thanks
adib
A: 

The documentation says that either should work, but the former (Purchases[SIZE] == 0) does not. A bug has been filed.

Note that using the @count operator is going to use a JOIN as an implementation detail which may not have the performance characteristics you desire/require.

Jim Correia