title: Delete a has_many through relationship without an id in the link table
body: <p>I would like to delete a relationship between the two models Project and Language. These two models are linked through a Link table which also stores extra parameters (is_default, ...)</p>
  
  <p>My models are </p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
      has_many :links
      has_many :languages, :through =&gt; :links
      # ...
  end
  class Link &lt; ActiveRecord::Base
      belongs_to :project
      belongs_to :language
  end
  class Language &lt; ActiveRecord::Base
      has_many :links
      has_many :projects, :through =&gt; :links
      # ...
  end
  </code></pre>
  
  <p>I tried this in Project controller :</p>
  
  <pre><code> # Removes a languages associated to a project (links table)
    def remove_language
      lang = current_project.links.where("language_id = ?", params[:id])
      current_project.links.delete(lang) if lang
  
      redirect_to project_path(current_project), notice: 'Language has been removed from project.' 
    end
  </code></pre>
  
  <p>But I get the following error :</p>
  
  <pre><code>ActiveRecord::UnknownPrimaryKey in ProjectsController#remove_language
  Unknown primary key for table links in model Link.
  </code></pre>
  
  <p>My routes.rb contains</p>
  
  <pre><code>resources :projects
  match 'projects/remove_language/:id' =&gt; 'projects#remove_language'
  match 'projects/add_language/:id' =&gt; 'projects#add_language'
  </code></pre>
  
  <p>I call my controller with this :</p>
  
  <pre><code>link_to "Remove", :controller =&gt; :projects, :action =&gt; :remove_language, :id =&gt; a.id
  </code></pre>