meaning-matters
meaning-matters

Reputation: 22946

How to do a nested CoreData query?

I have the following CoreData model: [Phone] <<--->> [Forwarding] <--->> [Number].

How do I build up a query that fetches a list of unique Numbers that are used by a Phone (so indirectly via its Forwardings)?

Upvotes: 0

Views: 410

Answers (1)

Martin R
Martin R

Reputation: 539685

Create a fetch request on the "Number" entity and add the predicate

[NSPredicate predicateWithFormat@"ANY forwarding.phones == %@", thePhone]

to the fetch request (assuming that the to-one relationship from "Number" to "Forwarding" is called "forwarding", and the to-many relationship from "Forwarding" to "Phone" is called "phones").

Upvotes: 3

Related Questions