Forum: Ruby on Rails setting up proper relationships

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
734a7bce0ec28ecc63ab0bc92cfa3182?d=identicon&s=25 Pawel Jur (pabloz)
on 2007-07-16 15:38
Hi

I am trying to make a small survey app and started to get a little
confused. So far i have

survey.rb
has_many :answers

answer.rb
belongs_to :survey

So Survey will have many answers, and answer will belong to only one
survey. This part works fine. Now i want to record survey results (you
can only pick ONE answer, it will NOT be a multiple answer survey).

To do this, as far as i know i should create anwsers_surveys table and
setup proper habtm relations or create a new model and go with :through.


Is this the way to go?, since i am not really trying to make a real
habtm between surveys and answers but need to record the results.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-07-16 15:48
(Received via mailing list)
why not just have a score column in the answers table?
391f9b787cdc12aa2c179713f5103e3a?d=identicon&s=25 Ilan Berci (iberci)
on 2007-07-16 16:23
Pawel Jur wrote:

>
> Is this the way to go?, since i am not really trying to make a real
> habtm between surveys and answers but need to record the results.

Pawel,

Step back from ActiveRecord for a bit and examine your problem domain.
If a survey can have multiple answers and and answer can have multiple
surveys then you have already answered your own question!  i.e.  you
will need a link table either with the habtm (deprecated) or the first
class model approach (:through)

I write this response with the assumption that "answer" is equivalent to
"result".  If I am mistaken then please forgive the confusion.

HTH ilan
734a7bce0ec28ecc63ab0bc92cfa3182?d=identicon&s=25 Pawel Jur (pabloz)
on 2007-07-16 18:38
Thanks for responses!

Chris Hall wrote:
> why not just have a score column in the answers table?

Yup. So simple solution and it fits just right for my problem. I gotta
start drawing my models and relations on paper before i start making
decisions i guess.


Ilan,

You are right if a survey could have multiple anwsers and answer can
have multiple  surveys but that's not the case. Chris solution fits.
This topic is locked and can not be replied to.