I like to have CoreData entities that resemble parent/children classes. The parent entity should be able to contain lots of children, each children could be a different kind of child entity. For example, the parent entity could resemble a page, the children entity could resemble text, images, or links. Then the app would show a page (parent) with all the children’s as content (with order).
I tried to create the parent entity with a to-many-relationship for the children, but the problem is, that the children must be of the same type. Since I do not want to keep track of ordering indices manually, I discarded the idea to have a to-many-relationship for each children type.
Hence, my next idea is to only track the children’s IDs in a set or array. The parent would then only hold a “pointer” to the children’s IDs. That way, I have no problem with different types of children. Now my question is, what is the best practice to do that? I thought about saving a JSON representation of the ID array (so basically a string that I have to process when making changes or loading the data in the UI). I also thought about having an “Identifier” entity that simply holds a UUID and parent entities would have a to-many-relationship without an inverse relationship to the “Identifier” entity.
What is a proven way to achieve a parent/children relationship, where the children can be of different type in a CoreData Model?