让我来描述一下我想做的事:
有匹配模式,它应该有什么球员,出席了在它什么氏族的信息,以居家球员分工和宗族客场球员和战队。
这很简单,但有另一种模式:召唤师。在每场比赛中,每名球员都有不同的召唤师,我需要做这样的事情: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