# How should I structure this model?

**URL:** <https://www.ruby-forum.com/t/how-should-i-structure-this-model/137328>\
**Category:** Rails\
**Created:** [May 12, 2008, 3:03am UTC](https://www.ruby-forum.com/t/how-should-i-structure-this-model/137328 "2008-05-12T03:03:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [May 12, 2008, 3:03am UTC](https://www.ruby-forum.com/t/how-should-i-structure-this-model/137328/1 "2008-05-12T03:03:57Z")

</div>

I have an application that is used by several different organizations.  
(each organization runs their own copy)

In the application, there are users, and each user can have a number of  
specialties. The specialties vary from organization to organization.  
Also,  
the possible specialties may change from time to time, according to the  
wishes of that particular organization.

Normally, I would think that I would create a specialties table with a  
has  
and belongs to many relationship with users. But I don’t want to be  
building different tables for each organization, and I want them to be  
able  
to add and delete specialties at will.

At the moment, I have a constant defined in my environment.rb that holds  
an  
array of the specialties (an array of strings). Then in each user, I  
have a  
serialized field that holds an array of the specialties appropriate to  
that  
user. But of course, the constant can’t be changed by the organization,  
and  
the whole thing is awkward for checkboxes, etc.

There has to be a better way, and I would me most grateful for any  
advice.

Shelby

---

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [May 12, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/how-should-i-structure-this-model/137328/2 "2008-05-12T17:18:05Z")

</div>

If a user belongs to an organization, go ahead and do what you  
suggested (habtm). The organization would only see their users’  
specialties because specialties would be related to users.

If a user can belong to multiple organizations, look into using  
\_with\_scope on your find statements.

-Kyle

---

<div class="post-metadata">

**Author:** ![Shelby\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19b73/32.png) [@Shelby\_W](https://www.ruby-forum.com/u/Shelby_W)\
**Post date:** [May 12, 2008, 7:16pm UTC](https://www.ruby-forum.com/t/how-should-i-structure-this-model/137328/3 "2008-05-12T19:16:03Z")

</div>

Sounds like you want to be able to drive this particular part of the  
application from a model, not from the environment.rb. Make that puppy  
data-driven for the specialties allowed within each organization.  
There’s no reason that data shouldn’t reside in a table. Even a basic  
scaffolded interface would let the right person (the organization’s  
admin user) create new specialties, etc, etc.

By “(each organization runs their own copy)”, do you mean that each  
organization has their own database? If not, the specialties just need  
an organization tag assigned to them to keep them separate in the  
processing, re: Kyle’s \_with\_scope suggestion.
