title: Remove association (for many to many) in Ecto
body: <p>I have a User and Program model which have a many-to-many association.
  They create associations successfully, so that a User has many Programs (and vice versa), but now I need to remove the association (but <strong>not delete</strong> the User or Program)</p>
  
  <p>I have a function in the ProgramController that associates them like so:</p>
  
  <pre><code># Myapp.ProgramController
  
  def associate_user(conn, _params) do
     %{"_csrf_token" =&gt; _csrf_token,"_method"=&gt;_method,"_utf8" =&gt; _utf8,"id" =&gt; id, "user" =&gt; %{"email" =&gt; email}} = _params
     {pid, _} = Integer.parse(id)
  
     user = Repo.get_by(User, email: email) |&gt; Repo.preload(:programs)
     program = Repo.get_by(Program, id: pid) |&gt; Repo.preload(:users)
  
     pid_list = user.programs
     |&gt; Enum.map(fn x -&gt; x.id end)
     |&gt; List.insert_at(0, program.id)
  
     changeset_list = from(program in Myapp.Program, where: program.id in ^pid_list)
     |&gt; Repo.all
     |&gt; Enum.map(&amp;Ecto.Changeset.change/1)
  
     from(user in User, where: user.email == ^user.email, preload: [:programs, :role])
     |&gt; Repo.one
     |&gt; User.changeset(%{})
     |&gt; Ecto.Changeset.put_assoc(:programs, changeset_list)
     |&gt; Repo.update!
  
     program = conn.assigns[:program]
     changeset = Program.changeset(program)
  
     conn
     |&gt; put_flash(:info, "Program updated successfully.")
     |&gt; redirect(to: program_path(conn, :edit, program))
   end
  </code></pre>
  
  <p>and I have a migration that creates a join table</p>
  
  <pre><code>defmodule Myapp.Repo.Migrations.AssociateUsersAndPrograms do
    use Ecto.Migration
  
    def change do
  
      alter table(:users) do
         add :current_program_id, references(:programs, on_delete: :nilify_all)
      end
  
      create table(:users_programs, primary_key: false) do
        add :user_id, references(:users, on_delete: :delete_all)
        add :program_id, references(:programs, on_delete: :delete_all)
      end
  
      create index(:users_programs, [:user_id])
    end
  end
  </code></pre>
  
  <p>How would I go about disassociating a particular user from a program as I did not see a delete_assoc in the Ecto.Docs?</p>
  
  <p>Still learning and loving Elixir (and Phoenix) so far so any help would be much appreciated!</p>