Something like this should work
class Team < ActiveRecord::Base
has_many :games
end
class Game< ActiveRecord::Base
belongs_to :hometeam, class_name: "Team", foreign_key: :hometeam_id
belongs_to :awayteam, class_name: "Team", foreign_key: :awayteam_id
end