0

I'm modelling the data model for an app and have a case where I want an entity to be able to contain entities of the same entity. This screenshot should clarify the case:

enter image description here

Item is an entity that can either be a stack or a card (determined by the 'type' attribute in it. If it's a stack it will have a relation to a StackProperties entity. However, Stacks can contain both cards and stacks (so stacks can be wrapped into stacks).

The 'items' relation in the StackProperties entity refers to any Items that could be in the stack, and these items could be either cards or stacks.

Question: Is this a proper way of modelling this scenario or is there a better way to achieve this structure? I'm asking because Xcode warns me that StackProperties.items has no inverse relationship, which isn't a good practice. How would this issue best be solved? Since Item already has a (two-way) relation to StackProperties (stackProperties <-> owner) I doubt it's a good solution to add another one for the 'items' relation, to make it inverse.

BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
  • holding references to each other in different entities is regular practice if the actual _queries_ (i.e. predicates) cannot extract the necessary information in more efficient way. the database's structure usually should be built up for serving _all_ mandatory queries on the most efficient way – therefore if you know what type of information you want to extract in runtime, you should built the hierarchy for those. – holex Aug 21 '14 at 08:43
  • Ok thanks, I will try changing the model structure. Is is probably better to make StackProperties and CardProperties to be actual sub-entities of Item anyway. – BadmintonCat Aug 21 '14 at 08:47

0 Answers0