Designing Database for Long Forms in Rails & ActiveRecord -
i want store complex form/questionnaire data i'm having hard time designing database:
a user can create new exam. when creating exam, user needs choose template 30 pre-set questions (and want store answer each of these questions in database).
purpose of template practitioners might want run different exams (e.g. knee exam, arm exam, spine exam etc). create new exam, choose specific template. , each template has many questions
what's best way design database? started creating exam, template, , question models, got lost building relationships.
here's how ended designing database. added 4th "answers" model. way, can associate answers questions, , questions templates, , templates exams.
hope helps someone
class user < activerecord::base has_many :patients has_many :assessments end class patient < activerecord::base belongs_to :user has_many :assessments end class assessment < activerecord::base belongs_to :user belongs_to :template belongs_to :patient has_many :questions, :through=> :template has_many :answers, :through=> :questions end class template < activerecord::base belongs_to :user has_many :questions end class question < activerecord::base belongs_to :template has_one :answer end class answer < activerecord::base belongs_to :question end
Comments
Post a Comment