Shandy Nantz wrote:
> I am trying to allow a user to answer some questions and then save those
> questions but I am unsure if I am getting the layout correct. Here is
> what I have so far:
> 
> There is a questions table holding the questions to ask
> 
> There is an answers tables which holds the answers to the questions
> asked of a user.
> 
> Then there is of course the Users table which hold a variety of user
> info
> 
> I figure my migrations would look something like:
> 
> Questions: has_many :answers
> 
> Answers: belong_to :user, belongs_to :question
> 
> User has_many :answers
> 
> so my table would look like:
> 
> User: id, username, . . .
> 
> Questions: id, question
> 
> Answer: id, user_id, question_id, answer
> 
> Where I am a little confused is if the belongs_to :question should
> rather be a has_one :question and would that change the schema at all?
> Also, can anyone point me to some good online tutorials involving Model
> Relationships, thanks,
> 
> -S

For what it's worth, I would probably do something like:

User:  has_many :questions
       has_many :answers

Question:  has_many :answers
           belongs_to :user

Answer:  belongs_to :question
         belongs_to :user

Tables:
User:     id | user_name
Question: id | user_id | question
Answer:   id | user_id | question_id | answer


hope this helps
-- 
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to