title: How to do bulk update in rails on habtm association
body: <p>I have two models:</p>
  
  <pre><code>#user.rb
  
  has_and_belongs_to_many :groups
  
  #group.rb
  
  has_and_belongs_to_many :users
  </code></pre>
  
  <p>I want to associate groups to users such that <code>many users can be associated to many groups</code>.</p>
  
  <p>Front end side of the application is sending the <code>user_ids</code> and <code>group_ids</code> to the update method.</p>
  
  <p>So in the <code>UsersController</code>, i've found out each user and associated that user with the groups.</p>
  
  <pre><code>def update
    users = User.where(id: [325, 326])
    users.each { |user| user.update(group_ids: [1, 2])}
  end
  </code></pre>
  
  <p>I need to know the standard way of updating the associated records and what is the most efficient way of updating associated records?</p>