0
我正在创建一个简单的游戏网站,用户可以创建游戏并邀请其他用户加入他们的游戏。用户可以通过:game_players
连接表既是游戏的所有者又是该游戏中的玩家(所有者也必须是玩家)。我希望这些球员被称为:player
,比赛的主人被称为:user
。我试图弄清楚如何设置关联。我的问题在下面的评论中:Rails与改名班HABTM协会
class User
has_many :games # This is the owner association
has_many :games_playing, class_name: 'Game', through: :game_players # is this right?
end
class Game
belongs_to :user # this is the owner association
has_many :players, through: :game_players
end
class GamePlayer
belongs_to :game
belongs_to :player, class_name: 'User'
# is this right? is it necessary?
end
我在正确的轨道上吗?