# How do I create this relationship in Rails? At least...what's the best way?

**URL:** <https://www.ruby-forum.com/t/how-do-i-create-this-relationship-in-rails-at-least-whats-the-best-way/144790>\
**Category:** Rails\
**Created:** [August 2, 2008, 1:40am UTC](https://www.ruby-forum.com/t/how-do-i-create-this-relationship-in-rails-at-least-whats-the-best-way/144790 "2008-08-02T01:40:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lefty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/85e7bf/32.png) [@Lefty](https://www.ruby-forum.com/u/Lefty)\
**Post date:** [August 2, 2008, 1:40am UTC](https://www.ruby-forum.com/t/how-do-i-create-this-relationship-in-rails-at-least-whats-the-best-way/144790/1 "2008-08-02T01:40:38Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Lefty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/85e7bf/32.png) [@Lefty](https://www.ruby-forum.com/u/Lefty)\
**Post date:** [August 2, 2008, 3:34am UTC](https://www.ruby-forum.com/t/how-do-i-create-this-relationship-in-rails-at-least-whats-the-best-way/144790/2 "2008-08-02T03:34:12Z")

</div>

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
