I really need some help solving this little puzzle in my app.
Case: I have, lets say 4 entities in Core-Data:
- MixColors (consist of 3 colors from ColorA,B and C. And many of them)
- ColorA
- ColorB
- ColorC
The user chooses 3 colors(A,B,C), and stores the result in MixColors. The 3 colors is just the ID from the color entities, the indexed ID (primary key). Entity mixcolors consist of ‘many’ combinations for those colors.
My bad solution: I can easily make the model without relationships.. but I prefer relations in core-data.
Problem: So how could I achieve this?
Should I combine ColorA,B,C into one entity: Color – and then make a single relationsship but I see some problems for the index IDs? So what’s the best way to model this case in core-data?
In core data you don’t have to worry about IDs at all, it’s all taken care of for you. Maybe try this:
You only need 2 objects and a one to many relationship between palette objects and color objects. In practice this will mean a Palette object will have a property called Colors, which will be an
NSSetof color objects. If the color objects have to also keep their order then add a property for that, like ‘order’ that stores a number. You can then fetch them in that order.