2012-07-23 43 views
0

我想實現一個遊戲模型,它有兩個團隊和兩個分數。一個團隊是一個玩家列表。導軌 - 模型設計 - 引用兩個相同型號的列表

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 

任何解決方案來實現這個?我不知道這是否可能。謝謝!

回答

1

最簡單的方法是創建一個Team模型,該模型有許多玩家並擁有得分。遊戲包含兩個團隊(實際上has_many)。這樣用戶不僅可以訪問遊戲,還可以訪問比分和隊友。 (如果你這樣做,要求球員的隊友不是一件容易的事)

你想要什麼是可能的,但我不會推薦這麼做。改爲添加Team模型。