# Column Names? Many-to-many on same table

**URL:** <https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527>\
**Category:** Rails\
**Created:** [September 5, 2006, 12:32am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527 "2006-09-05T00:32:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2006, 12:32am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527/1 "2006-09-05T00:32:32Z")

</div>

Hi folks,

I’m putting together an app to track scores for a kids sports league,  
and I can’t figure out how to name the columns in my “games” table.  
I’ll need a “home team ID” column and an “away team ID” column, but  
since they both reference the “teams” table, Rails conventions would  
give them both the name “team\_id”, which is obviously not going to  
work.

I’ve googled, and I’ve looked in the wiki, but I can’t seem to find any  
documentation on how to handle a situation like this. How would you  
guys do it?

Also, is there a way for the many-to-many table to represent an object  
with its own properties rather than being merely a link between two  
other objects (e.g. a game has a date)?

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2006, 1:46am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527/2 "2006-09-05T01:46:39Z")

</div>

class Game  
belongs\_to :home\_team, :class =\> ‘Team’, :foreign\_key =\>  
‘home\_team\_id’  
belongs\_to :away\_team, :class =\> ‘Team’, :foreign\_key =\>  
‘away\_team\_id’  
…  
end

class Team  
has\_many :games  
end

removed\_email\_address@domain.invalid wrote:

> >

–  
View this message in context:  
[http://www.nabble.com/Column-Names---Many-to-many-on-same-table](http://www.nabble.com/Column-Names---Many-to-many-on-same-table)…-tf2217762.html#a6143691  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2006, 3:36am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527/3 "2006-09-05T03:36:46Z")

</div>

Aha - that makes waaay too much sense! Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2006, 2:22am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527/4 "2006-09-05T02:22:42Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I’m putting together an app to track scores for a kids sports league,  
> and I can’t figure out how to name the columns in my “games” table.  
> I’ll need a “home team ID” column and an “away team ID” column, but  
> since they both reference the “teams” table, Rails conventions would  
> give them both the name “team\_id”, which is obviously not going to  
> work.
> 
> I’ve googled, and I’ve looked in the wiki, but I can’t seem to find any  
> documentation on how to handle a situation like this. How would you  
> guys do it?
> 
> Also, is there a way for the many-to-many table to represent an object  
> with its own properties rather than being merely a link between two  
> other objects (e.g. a game has a date)?

I’ve got a few articles on my blog that have relevant information, but  
you should start with this one:  
[http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through](http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through)

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2006, 3:36am UTC](https://www.ruby-forum.com/t/column-names-many-to-many-on-same-table/67527/5 "2006-09-05T03:36:46Z")

</div>

Thanks, I’ll take a look.
