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?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Jeremy Walker at May 2, 2012 at 9:40 pm

    On 2 May 2012, at 21:25, Greg Ma wrote:

    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 http://github.com/ihid/super_sti might help. Email me personally if you want some help with that repository.

    Jeremy Walker
    http://www.ihid.co.uk
    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?

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Robert Walker at May 2, 2012 at 10:16 pm

    Jeremy Walker wrote in post #1059314:
    On 2 May 2012, at 21:25, Greg Ma wrote:

    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
    http://github.com/ihid/super_sti might help. Email me personally if you
    want some help with that repository.
    Here's a direct and elegant solution: http://www.mongodb.org/
    If rigid schema is the problem, then eliminate your dependence on a
    pre-defined schema.

    However, the STI solution mentioned above is probably the next best
    approach.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMay 2, '12 at 8:26p
activeMay 2, '12 at 10:16p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Robert Walker: 2 posts Jeremy Walker: 1 post

People

Translate

site design / logo © 2021 Grokbase