On Nov 1, 2007, at 9:05 PM, Pootsy wrote:> Hi,
>
> I''m looking to model a set of fixtures for a sports league.
>
> I''ve got a team model {id*, name}
> And a match model {id*, date, homeTeam, homeScore, awayTeam,
> awayScore}
>
> I''d like the team.id to appear in the match.homeTeam and
> match.awayTeam (ie. twice in the same record) as one team plays
> another in a given match. How would I go about modelling this in
> Rails?
>
> I understand that in MySQL you select team.id twice giving each a
> different alias.
>
> Thanks a lot,
>
> Pootsy
class Match < ActiveRecord::Base
belongs_to :home_team, :class_name => ''Team'',
:foreign_key
=> :home_team_id
belongs_to :away_team, :class_name => ''Team'',
:foreign_key
=> :away_team_id
end
Note that the :foreign_key is required in Rails 1.2 (the default being
the class name with "_id"), but will be redundant in Rails 2.0 as the
default will be built from the association name.
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---