Column with dynamic db type

Hi,

I have a Question model where the answer to the question can have multiple db type (integer, string, boolean, ...).

I would like to know if you have a better solution than this one:

Question: question:string answer_type:string

AnsweredQuestion: question_id:integer answer:text answer_type:string

Ex: AnsweredQuestion.create(:question => 1, :answer => '5', :answer_type => 'Integer')

My problem with this solution is that I can't question is that I can't question the answered questions where the answer is > 2.

Any better idea?

Hi,

I have a Question model where the answer to the question can have multiple db type (integer, string, boolean, ...).

I've had a similar situation. I'd use STI to have different models for different answer types. My repository at GitHub - iHiD/super_sti: Add extra data to SDI models yet maintain clean database tables. might help. Email me personally if you want some help with that repository.

Jeremy Walker http://www.ihid.co.uk

Jeremy Walker wrote in post #1059314: