title: Ecto put_assoc why preload and why require id
body: <p>I'm getting rather confused about Ecto when it comes to adding a new association to an existing model. Let's say I have some discussion board where users can like a post, and I have the following models:</p>
  
  <pre><code>  schema "discussion_items" do
      many_to_many :likes, XXX.Tag, join_through: "discussion_items_likes"
      timestamps()
    end
  
    schema "likes" do
      belongs_to :user, XXX.User
      timestamps()
    end
  </code></pre>
  
  <p>Now lets say I have an existing <code>DiscussionItem</code> and I want to add a like association to this, here's what Im trying (simplified):</p>
  
  <pre><code>user = Repo.one(User)
  discussion_item = Repo.one(from d in DiscussionItem, preload [:likes])
  
  like_changeset = Like.changeset(%Like{})
                       |&gt; Ecto.Changeset.put_assoc(:user,   user)
  changeset = Ecto.Changeset.change(discussion_item) 
                  |&gt;  Ecto.Changeset.put_assoc(:likes, [like_changeset])
  
  Ecto.update!(changeset)
  </code></pre>
  
  <p>What I am finding is that this will create the Like and the association correctly the first time but then complain afterwards that I need additional information in the form of some id:</p>
  
  <blockquote>
    <p>you are attempting to change relation :likes of XXX.DiscussionItem,
    but there is missing data</p>
    
    <p>If you are attempting to update an existing entry, please make sure
    you include the entry primary key (ID) alongside the data.</p>
    
    <p>If you have a relationship with many children, at least the same N
    children must be given on update. By default it is not possible to
    orphan embed nor associated records, attempting to do so results in
    this error message.</p>
  </blockquote>
  
  <p>So here's the things that confuse me (there are a few):</p>
  
  <ol>
  <li>This error message seems to suggest that in order to update one associated item, I need to provide a change set with ALL items including the one that changed. This seems nuts, so I'm guessing I'm reading this wrong.</li>
  <li>I don't want to update the likes association -- I want to add one. Is put_assoc the wrong choice here?</li>
  <li>Do I really need to preload the likes just to insert an item? Even on update I don't want to load the whole collection of associations to change one. </li>
  <li>Do I need to load <code>User</code> and <code>Dicussion_item</code> to add a like here?</li>
  </ol>