# One Lookup Table for Multiple Properties in a Model

**URL:** <https://www.ruby-forum.com/t/one-lookup-table-for-multiple-properties-in-a-model/88084>\
**Category:** Rails\
**Created:** [March 7, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/one-lookup-table-for-multiple-properties-in-a-model/88084 "2007-03-07T23:58:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [March 7, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/one-lookup-table-for-multiple-properties-in-a-model/88084/1 "2007-03-07T23:58:23Z")

</div>

How can one use the same lookup table for multiple columns in the same  
table?

e.g. let’s say I have a lookup table with automobile makes (Audi, BMW,  
Chevrolet) , and then a “drivers” table with columns for primary car  
make, secondary car make, etc. I can’t very well name them both  
make\_id…?

Many thanks,

Brian

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [March 8, 2007, 12:08am UTC](https://www.ruby-forum.com/t/one-lookup-table-for-multiple-properties-in-a-model/88084/2 "2007-03-08T00:08:24Z")

</div>

> How can one use the same lookup table for multiple columns in the same  
> table?
> 
> e.g. let’s say I have a lookup table with automobile makes (Audi, BMW,  
> Chevrolet) , and then a “drivers” table with columns for primary car  
> make, secondary car make, etc. I can’t very well name them both  
> make\_id…?

Change the key name in your has\_one/belongs\_to lines with:

:foreign\_key - specify the foreign key used for the association. By  
default this is guessed to be the name of this class in lower-case and  
“\_id” suffixed. So a Person class that makes a has\_one association will  
use “person\_id” as the default foreign\_key.

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [March 8, 2007, 12:52am UTC](https://www.ruby-forum.com/t/one-lookup-table-for-multiple-properties-in-a-model/88084/3 "2007-03-08T00:52:31Z")

</div>

You’ll need :class\_name, too.

class Driver  
belongs\_to :primary\_make, :class\_name =\> ‘Make’, :foreign\_key =\>  
‘pri\_make\_id’  
belongs\_to :secondary\_make, :class\_name =\> ‘Make’, :foreign\_key =\>  
‘sec\_make\_id’  
belongs\_to :favorite\_make, :class\_name =\> ‘Make’, :foreign\_key =\>  
‘the\_best\_make\_id’  
…

– Wes
