1

Example) Building a site where there is a hierarchal structure like so: Territory -> Gang -> Wizard.

Each one of these objects will have very close to the same columns (uid, wins, losses, hp etc..). Users can create territories (different types of territories), gangs, and wizards. Wizards can be a direct child of territory.

Would it make sense to store all three objects in a single table with different tables based on the territory type?

skaffman
  • 398,947
  • 96
  • 818
  • 769
unpollo
  • 806
  • 5
  • 15

2 Answers2

2

No, (in my opinion) it wouldn't make sense to do that. They are different kinds of things, so they should be stored in different tables.

If they have some aspect in common, then you could make a single table that stores that aspect with appropriate foreign key relationships to or from the correct entities. But they are mainly different kinds of things, so they should be separated.

For example, territories cannot contain other territories, though they can contain gangs. Therefore, the entities are dissimilar in important ways, and should be stored separately.

Jeffrey L Whitledge
  • 58,241
  • 9
  • 71
  • 99
2

This looks like a case of the gen-spec design pattern, in addition to being organized in a hierarchy because of their relationships to each other.

The gen-spec pattern has been discussed several times. See previous discussion.

Once you have a single generalized table, in addition to the specialized table, you can model the hierachy in that table, using either the adjacency list method, or the nested-set method. In your case, I would use nested set.

Community
  • 1
  • 1
Walter Mitty
  • 18,205
  • 2
  • 28
  • 58