We are building a survey engine for our internal use. I would like to know how to persist the question branching logic into the database? Any body done this before or any ideas
You're essentially looking to persist a decision tree into a database. You'd want to store each question as a node and, in the interests of a normalized database, store the edges in a separate table relating questions that depend on other questions (directed edges), and walk as appropriate.
Edit: A simple design can be two tables: Questions and Edges. Questions just has id
and question text
. Edges can be answered_question_id
, next_question_id
, and answer
. The first table is self-explanatory. The second table lists that if a question answered_question_id
is asked and answered with something that either equals to or matches answer
, forward to question next_question_id
next.