# Confusion about models and support tables

**URL:** <https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546>\
**Category:** Rails\
**Created:** [October 9, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546 "2006-10-09T19:48:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [October 9, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546/1 "2006-10-09T19:48:22Z")

</div>

Hi, All,

On October 6 Michael S. asked the following question:

“When the generate script creates a model, it creates a subclass of  
ActiveRecord. Is this to say that every table - even pure support tables  
such as a table for state codes - should have a model?”

Mario Cicio responded with:

“No, on the contrary this is to say that every model is supposed to have  
a persistency attached (simple case: 1 table).  
The most common case of a table not having a model attached is the “join  
table” in a habtm relationship.”

This created a bit of confusion for me and I’m not sure whether I  
just read thing wrong or what. So I thought it was time to reveal my  
ignorance by asking for a bit of clarification.

Let’s say I have a support table, say a list of states the user can  
choose from. If I do not have a “State” model, how do I access the  
table in my controller. Without the model, I can’t do  
State.find :first, :conditions =\> X, can I? How, then do I look up a  
state in the table? Am I just way off here, or what?

I guess I’m asking is what is the best way to handle support tables  
like states, cities, appointment types, etc.?

Dave

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [October 9, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546/2 "2006-10-09T22:46:54Z")

</div>

If you don’t want the overhead of a model for certain data, you can  
always just make direct queries on the database.

For the cases you mentioned, though, I would probably just do the easy  
thing and make them into models. Models aren’t just for the major  
things.

Those cases also differ from the HABTM (Has and belongs to many)  
support table. That table’s sole purpose is to join to things together.  
It’s not really a “thing” itself because it doesn’t have any of its own  
attributes.

Cheers  
Starr

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [October 9, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546/3 "2006-10-09T23:53:02Z")

</div>

On Oct 9, 2006, at 1:42 PM, Starr wrote:

> If you don’t want the overhead of a model for certain data, you can  
> always just make direct queries on the database.

I guess this is where my question is. How would I directly query a  
database in rails? I’ve always used a model and used Model.find.

> For the cases you mentioned, though, I would probably just do the  
> easy  
> thing and make them into models. Models aren’t just for the major  
> things.

I’m with you here. I’ve always used a model for these kinds of  
tables. I was just thrown a bit by the thought of doing it  
differently. My curiosity was piqued. Hate it when that happens. 🙂

> Cheers  
> Starr

Thanks for the response, Starr. I appreciate it.

Dave

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [October 10, 2006, 6:09am UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546/4 "2006-10-10T06:09:32Z")

</div>

On 10/9/06, David P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Let’s say I have a support table, say a list of states the user can  
> choose from. If I do not have a “State” model, how do I access the  
> table in my controller. Without the model, I can’t do  
> State.find :first, :conditions =\> X, can I? How, then do I look up a  
> state in the table? Am I just way off here, or what?
> 
> I guess I’m asking is what is the best way to handle support tables  
> like states, cities, appointment types, etc.?

This is handled pretty well by virtual enumerations:

[http://svn.protocool.com/rails/plugins/enumerations\_mixin/trunk/](http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk/)

just insert the data in a migration and you have a nice interface to  
the data, and simple too.

pt.

> Dave
> 
> >

–  
Parker T.

> **[ParkErt.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=parkert.com)**
>
> Join thousands of people who own a premium domain. Affordable financing available.

510.541.0125

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [October 10, 2006, 4:21pm UTC](https://www.ruby-forum.com/t/confusion-about-models-and-support-tables/71546/5 "2006-10-10T16:21:02Z")

</div>

That’s pretty cool. You learn something new every day - thanks parker!

Starr
