我是Rails的一名初学者,但随时都在学习。我正在尝试创建一个锦标赛入场门户网站,一个球队可以进入参加锦标赛的选手。我已经完成了关于关联的一些阅读,但是在这种情况下如何应用它们会遇到一些麻烦。比赛 - >球队 - >球员协会
作为基本概述:
- 一个比赛,有很多球队。
- 每队有很多球员
- 因此一个巡回赛也有不少玩家(通过团队
进入)
这里是我这个代码,但我不知道这是正确的,因为我无法获得与玩家相关的任何tournament_ids。
(tournament.rb)
class Tournament < ApplicationRecord
has_many :teams
has_many :players, :through => :teams
end
(team.rb)
class Team < ApplicationRecord
belongs_to :tournament
has_many :players
end
(player.rb)
class Player < ApplicationRecord
has_one :team
has_one :tournament, :through => :team
end
内玩家桌子上有两个TEAM_ID & tournament_id字段,但是我只能通过关联来填充team_id字段,当我尝试使用CONSOL时即
我想知道是否有什么与我的协会不协调。
出于兴趣如何使用TeamTournament模型?我在这个地方的几个不同的答案和例子中看到了一个类似的概念,但我无法让我的头脑围绕使用/概念 - 可能缺乏经验。 – afishintaiwan