How do I query/filter a to-many relationship in Core Data
Posted
by Kris Bixler
on Stack Overflow
See other posts from Stack Overflow
or by Kris Bixler
Published on 2010-05-19T16:02:28Z
Indexed on
2010/05/19
19:00 UTC
Read the original article
Hit count: 265
I have Customer, Event and Address objects in my data model. Both Customer and Address have a one-to-many relationship to Event.
I can get the distinct list of addresses for a customer's events for by doing this:
NSSet *addressSet = [customer valueForKeyPath:@"events.address"];
For the part of the UI I'm working on now, I need to display the address from the most recent event prior to now that has an address.
I'm starting to go down the path of creating a NSFetchRequest, setting it's entity, sort descriptors, predicate and then looping through the results, but it seems like a lot of code. Am I missing some obvious way of filtering/sorting on the "events" relationship of the Customer object or is creating the NSFetchRequest the best solution?
© Stack Overflow or respective owner