SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sports Match Model

    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 it twice giving each a different alias.

    Thanks a lot,

    Pootsy

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code ruby:
    class Team
      has_many :home_matches, :foreign_key => 'home_team_id', :class_name => 'Match'
      has_many :away_matches, :foreign_key => 'away_team_id', :class_name => 'Match'
    end
     
    class Match
      belongs_to :home_team, :foreign_key => 'home_team_id', :class_name => 'Team'
      belongs_to :away_team, :foreign_key => 'away_team_id', :class_name => 'Team'
    end


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •