Reputation: 3
I have a Core Data object called Car that has a one-to-many relationship with another Core Data object called Claims (i.e., one Car has many Claims). I've created the entities in the data model editor, and am able to list, edit, and work with the Car objects.
What I can't figure out is this: given a Car, how to get an array of all related Claim objects. I think it requires a fetch request, but how does it work?
Thanks!
Upvotes: 0
Views: 297
Reputation: 22116
If the entities are related, you'll want to add a relationship to your models. In core data relationships are two-way, so Car
would have a to-many relationship called "claims" and Claim
would have a to-one relationship called "car".
Having these relationships in place will give an instance of Car
an NSSet
of claim objects.
Upvotes: 3