title: Update tags lists - or updating has_many relationships
body: <p>I often meet the problem of updating <em>has many</em> relationships.
  For example, let's take the following three tables:</p>
  
  <ul>
  <li>posts</li>
  <li>tags</li>
  <li>posts_tags</li>
  </ul>
  
  <p>When a user creates a new post, he can add tags to the post. Post is saved, and the selected tags are attached to it via _posts_tags_.</p>
  
  <p>When user edits the post (and may or not edit the tag list too), and the form is submitted I have to update the post's tag list.</p>
  
  <p>A solution can be the following: when updating a post, I delete all tags of that post from _posts_tags_, and insert the submitted ones.</p>
  
  <p>Another solution is to get all tags of the post from db, compare the list with the submitted one and decide what we have to delete and what we have to insert.</p>
  
  <p>Both solutions can be time consuming.<br/>
  <strong>What is a more clever solution for the problem?</strong></p>