Column Names? Many-to-many on same table

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!

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

[email protected] wrote:


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

Aha - that makes waaay too much sense! Thanks!

[email protected] 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


Josh S.
http://blog.hasmanythrough.com

Thanks, I’ll take a look.