views:

23

answers:

2

Hello,

Assume you have an entity called Library and each Library can contain Books. It is possible for a Library to have no books at all. Is it possible to filter a fetch request so I only retrieve the Libraries that contain books?

I have read that you can use the SIZE tag for NSArrays (for example, myArray[SIZE]) in an NSPredicate, but this tag does not seem to work for NSSets (in a to-many relationship in Core Data).

Is there an equivalent tag that can be used to count the number of Books in a Library and filter the results based on this?

+3  A: 

You can use books.@count, assuming books is the to-many relationship from Library to Book.

Barry Wark
Exactly what I needed! Thanks a lot, Barry.
bare_nature
A: 

You might try defining a custom property for your NSManagedObject that computes and returns the count. Basically go in and define a custom method for a read-only property instead of using @synthesize or @dynamic that calls count on the nsset, then use the predicate on that.

Nimrod