Quantcast
Channel: Polymorphism in databases - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Polymorphism in databases

$
0
0

I would like to model a database entity for a set of players.Each player should have :

  • a number of fixed fields (name, role, ...)
  • a number of variable fields for skill levels (if role is ATK, skills should be stat1 and stat2; if role is DEF, skill should be stat3 and stat4).

What is the best way to implement such an entity (both relational and non-relational databases are fine for me)?

The most trivial solution is of course to hold a different table for each role. I also have found this answer, which is nice but is 7 years old and maybe outdated. Other ideas?


Here is a sample data set:

"name": "name1""role": "attack""strength": 10"constitution": 5"name": "name2""role": "attack""strength": 7"constitution": 7"name": "name3""role": "defense""health": 8"resistence": 8"name": "name4""role": "defense""health": 10"resistence": 10"name": "name5""role": "support""mana": 4"willpower": 3

Viewing all articles
Browse latest Browse all 3

Trending Articles