I'm creating a simple game site where users can create games and invite other users to join their games. A User can be both an owner of a Game and a player within that Game (the owner must also be a player) through the :game_players
join table. I want the players to be known as :player
and the owner of the game to be known as :user
. I'm trying to figure out how to set up the associations. My questions are in the comments below:
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
Am I on the right track here?