vincent15000's avatar

Database design to save a diagram

Hello,

I work on a personal project : an application to create treasure hunts to discover a location.

  • a treasure hunt has one or several quests

  • each quest can has one or several challenges

  • each challenge has one or several riddles

But ... if all challenges are binded to the treasure hunt (start-shaped treasure hunt), they can also be binded to other challenges (one step at a time).

And a challenge can even be binded to 2 other challenges, for example A is binded to B and C, and B and C are binded to D. In this example the solution to the challenges B and C are clues to solve the challenge D.

A quest, a challenge and a riddle are nodes, links between challenges are edges.

To store the edges into the database, I can use a many to many polymorphic pivot table.

  • id

  • from_type

  • from_id

  • to_type

  • to_id

  • meta

Perhaps you have a better idea to store the edges into the database ?

Thanks for your help.

V

0 likes
1 reply
Tray2's avatar
Tray2
Best Answer
Level 73

So I would probably go with this kind of database model.

treasure_hunts

  • id
  • title

quests

  • id
  • title

quest_trasure_hunt

  • treasure_hunt_id
  • quest_id

challanges

  • id
  • description

challange_quest

  • challange_id
  • quest_id

riddles

  • id
  • question
  • correct_answer_id

answers

  • id
  • answer
  • riddle_id

riddle_user

  • riddle_id
  • user_id
  • answer_id

quest_user

  • quest_id
  • user_is

Then progress is tracked through the riddle_user table.

1 like

Please or to participate in this conversation.