title: Rails has_many through and has one through multiple associations with form
body: <p>I'm having some trouble figuring out how to create a certain association. I have a Game model and a Console model. They're joined with a GamesConsole model via has_many through association. I also have a User model. </p>
  
  <p>What I want is users to be able to have games. But I want them to be able to pick one or multiple consoles that they own that game for. So I created an Ownership model that belongs to a user and a games_console, that way it gets a game_id and console_id from the games_console. </p>
  
  <p>First of all, I'm not sure if that's the correct or best way to set that up. But my main question is how to make a form to create/edit these Ownerships. I want the form to be on the Games#show view and to have a checkbox for each console available for the specific game. You'd check the consoles you own the game for and click the submit button. Doing that would create the necessary ownerships as well as delete some if you uncheck consoles that you previously owned the game for.</p>
  
  <p>I've tried playing with collection_check_boxes for the form but I'm not sure how to set it up or how to set up the controller. This association is more complicated than ones that I've used before. Any help would be much appreciated.</p>
  
  <p>My models:</p>
  
  <pre><code>class User &lt; ApplicationRecord
    has_many :ownerships
    has_many :games_consoles, through: :ownerships
    has_many :games, -&gt; { distinct }, through: :games_consoles
    has_many :consoles, -&gt; { distinct }, through: :games_consoles
  end
  
  class Console &lt; ApplicationRecord
    has_many :games_consoles
    has_many :games, through: :games_consoles
    has_many :ownerships, through: :games_consoles
    has_many :users, -&gt; { distinct }, through: :ownerships
  end
  
  class Game &lt; ApplicationRecord
    has_many :games_consoles
    has_many :consoles, -&gt; { order(:name) }, through: :games_consoles
    has_many :ownerships, through: :games_consoles
    has_many :users, -&gt; { distinct }, through: :ownerships
  end
  
  class GamesConsole &lt; ApplicationRecord
    belongs_to :game
    belongs_to :console
    has_many :ownerships
  end
  
  class Ownership &lt; ApplicationRecord
    belongs_to :user
    belongs_to :games_console
    has_one :game, through: :games_console
    has_one :console, through: :games_console
  end
  </code></pre>