Reputation: 3455
I am struggling with designing a coreData
model where I have only one type of entry called "To-Do". Each To-Do entry has either 0, 1, 2, ... , or n relationships to other (sub) entries just like To-Do. So the relationships between the To-Do entries design a tree structure with an undefined number of child nodes. The following graphic should illustrate the case (E = core data entry):
E
/|\
/ | \
E E E
/ \
/ \
E E
/|\
E E E
My guess was to model that data like illustrated in the following graph. I didn't choose the inverse relationship because Xcode made a many-to-many relationship out of it which doesn't match the tree design.
Also I saw in the data model inspector
something called "parent entry". So I started to believe I might have to create a second entry named "To-Do-Child" with the same attributes and make the other entry to the parent entry. The manual tells me that this might be the wrong path to go...
Questions:
How can I model this approach within the core data model file? Is one of the ones mentioned correct?
How will I be able to fetch all To-Do entries of a specified parent node? Since they arise from the same entry I have problems to address the exact To-Do subtree I want.
Upvotes: 5
Views: 1917
Reputation: 119262
I think you need a relationship of parent
(destination entity is your to do entity) which serves as the destination for the inverse relationship.
Entries at the top of the tree have nil value for this relationship.
For any to-do item, the set returned from the childToDos relationship will hold all the children. It doesn't matter that these are of the same class.
Upvotes: 4