I would like to implement a Game model, which has two teams and two scores. A team is a list of Players.
class Game < ActiveRecord::Base
has_many :players, :name => 'Team1' # I'd like this to be the first team
has_many :players, :name => 'Team2' # and this to be the second team
attr_accessible :score1 #the first team's score
attr_accessible :score2 #the second team's score
end
class Player < ActiveRecord::Base
attr_accessible :name
end
Any solution to implement this? I don’t know if/how this is possible. Thanks!
The easiest way is to create a
Teammodel, which has many Players, and holds a score. The game contains two Teams (actually has_many). This way the user can access not just the game, but the score and teammates as well. (If you do it like you want to do, asking for a player’s teammates is not an easy task)What you want is possible, but I would not recommend doing it. Add the Team model instead.