ringemup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-04 22:23 UTC
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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 ringemup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > > 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! > > > > > >-- 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ringemup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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 Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ringemup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-05 01:27 UTC
Re: Column Names? Many-to-many on same table...
Aha - that makes waaay too much sense! Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ringemup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-05 01:28 UTC
Re: Column Names? Many-to-many on same table...
Thanks, I''ll take a look. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---