讓我來描述一下我想做的事:
有匹配模式,它應該有什麼球員,出席了在它什麼氏族的信息,以居家球員分工和宗族客場球員和戰隊。
這很簡單,但有另一種模式:召喚師。在每場比賽中,每名球員都有不同的召喚師,我需要做這樣的事情:Match.find(1).players_home.find(1).Summoner.name
來提取哪位召喚師在主隊參加了比賽。
重點是:每場比賽中的每名球員都可以使用不同的召喚師進行比賽。
我希望我描述清楚。
此致敬禮。幫助與Rails的協會
0
A
回答
1
我真的不知道你所有的規格就當一個關聯是一個或幾個,但我覺得這樣的事情可能是它:
class Match
has_many :participations
has_many :players, :through => :participations
end
class Participation
belongs_to :match
belongs_to :player
belongs_to :summoner
# also a team attribute to store either "home" or "away"
scope :home, where(:team => "home")
scope :away, where(:team => "away")
end
class Player
belongs_to :clan
has_many :participations
has_many :matches, :through => :participations
end
class Summoner
has_many :participations
end
在此設置每場比賽有幾個參股。每一次參與都屬於參與的玩家,並且也屬於該玩家的召喚者和匹配。然後它可以或許利用這樣的:
在控制器
@match = Match.find(1)
@home_participations = @match.participations.home
@away_participations = @match.participations.away
在查看
<h1>Home Players</h1>
<% @home_participations.each do |p| %>
<p>Player: <%= p.player.name %>, Summoned by: <%= p.summoner.name %></p>
<% end %>
我希望這至少是有點什麼你要去的地方。讓我知道你是否在尋找別的東西。
+0
非常棒的解決方案,謝謝! – methyl 2011-03-17 11:58:58
相關問題
- 1. 幫助與rails協會
- 2. Rails協會的幫助
- 3. 幫助與軌道協會
- 4. 幫助協會在Rails 3的
- 5. Rails窗體幫助has_one belongs_to協會
- 6. Rails的simple_form與選項標籤協會的幫助
- 7. CakePHP 2請幫助模型協會
- 8. Cakephp hasmany,屬於協會需要幫助
- 9. 幫助理解polymophic協會(導軌)
- 10. belongs_to has_many協助幫助
- 11. 幫助與Rails find_by查詢
- 12. Rails幫助與設計
- 13. Rails'在哪裏'與協會
- 14. Rails嵌套協會與first_or_create
- 15. Rails教程:會話幫助中的NameError
- 16. Rails的has_and_belongs_to_many協會
- 17. Rails的has_many_through協會
- 18. 的Rails協會HAS_MANY
- 19. 協會在Rails的
- 20. Rails的HAS_ONE協會
- 21. Rails協會
- 22. Rails ActiveRecord協會
- 23. Rails HABTM協會
- 24. Rails協會:HABTM?
- 25. Rails協會
- 26. Rails ActiveRecord協會
- 27. Corp軟件 - 協作幫助?
- 28. 協議通信幫助
- 29. Exchange AirSync協議幫助
- 30. Rails的:我在與遺傳協會
那麼問題是什麼?你有一些代碼給我們看? – Wukerplank 2011-03-17 10:21:17
問題是如何設置關聯和模型。 – methyl 2011-03-17 10:31:51