I am new to Core Data modeling, and I am having a hard time understanding how one-to-many relationships work.
I have a parent entity called Task
, which can have several instances of Comment
entity. I modeled it like this: on Comments
, a relationship to Task
called task
with the Task
entity a destination. On Task
, a relationship called comments
, with Comment
as its destination, and both relationships are each others inverse.
Not defining an inverse results in either warnings or error messages. While modeling this way works, I've noticed that once I create a second comment for a given Task
, the first is replaced (one-to-one relationship).
What would be the correct way to tell the Core Data Model that this relationship allows many comments in one Task
?
Also, since CoreData seems to manage primary keys on its own, how would I create an NSPredicate
to retrieve all comments for a given Task?
Thanks for any suggestions!