Lets say we have the following entities.
- Entity A
- Entity B
- Entity C
The hierarchy
- A has many Bs.
- B has many Cs Each
- C has a value of string called name.
I have three view controller each displaying a list of entities. First view displays Entities A. Upon clicking on entity A, it lists all the entities B in that particular A. Upon clicking on B, it lists all the entities C in that particular B.
I add an A FirstA. First A has 3 B’s. Each of those B’s has 7 Cs.
This currently exists in core data. Lets say I want to add a new C called ‘marvelous_C’ into an arbitrary B.
Now here is the part that confuses me the most. Currently in my mind, i would add it like this. List out all the As. (in this case 1). Look at all the B’s FirstA has until i find the B i want to add marvelous_C to. I find this b, then append another C to the list of already existing C’s. Save in core data.
This to me seems rather unwise. Is there a better way to do this? Is there a model i can follow for this? Lets say im looking at the last view (the one that displays entities C in a particular B). is there anyway to add it to that particular set without having to go through the entire hierarchy?
this post may be confusing. standing by for any clarifications. thanks!
In your top view controller displaying the
Cs where you want to add another one, just keep a reference to the currentB. This could be a@propertyof the view controller in question.This should be the simplest solution.