Lefty
2008-Aug-01 23:08 UTC
How do I create this relationship in Rails? At least...what''s the best way?
I have a model, let''s call it an Assessments model. This model describes a collection of questions I''m developing to profile a user. So the first one is maybe a travel assessment. It consists of a few questions related to travel. Another assessment may be a sports assessment. This will find out what types of sports/recreational activities you like through a variety of questions. Now each assessment has_many questions. For travel it may be, do you like warm or cold climates? Each question has_many Answer Choices, which may be yes, no, maybe, sometimes, or a variety of other options. And then each question will also has_one answer, per user, that has a FK to the Users table and Question Table. This should give you an idea of what an assessment is. Now, each assessment has a profile. So the travel assessment will allow the user to create a travel profile. And the sports assessment will allow a sports profile (think online profile or something with descriptions, interests, etc). My question is: How can I model these profiles? They can''t really use STI because while there are a few overlapping similarities in the profiles, I may eventually have 30 assessments and 20 different fields per profile - so over 600 fields in that one table (with STI). Polymorphism doesn''t work because I don''t have enough duplication between the profiles. So what can I use? I''ve thought about creating a different model for each profile. Like a TravelProfiles model and a SportsProfiles model. But this seems like a lot of programming work per new assessment added. Then I thought about adding a ProfileFields model that will allow you to add a new row for a field and add an assessment type FK to that table. The only problem is, how do I deal with different data types? Like if one field is a multiple choice, where should I store the multiple choices? Or even if it''s a yes/no question, how do I store that in the database and make use of the data in the view? Ugh..sorry, long question! Thanks for any insight! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff Pritchard
2008-Aug-02 01:34 UTC
Re: How do I create this relationship in Rails? At least...
Lefty wrote:> > > My question is: How can I model these profiles? They can''t really > use STI because while there are a few overlapping similarities in the > profiles, I may eventually have 30 assessments and 20 different fields > per profile - so over 600 fields in that one table (with STI).> Ugh..sorry, long question! Thanks for any insight!I guess I don''t see how the profiles are different from the assessments. Just more questions per type? It may be a drag creating all of those profiles and their questions, but I don''t see how the size of that table is any concern. So it has 600 rows in it, no big deal. Imagine a "user" table on a busy site that has been around for awhile; that table would have many thousands of rows. I think you haven''t made your concern clear yet. thanks, jp -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---