title: Rails: Has and belongs to many (HABTM) -- create association without creating other records
body: <p>Spent all day on Google, but can't find an answer. :\</p>
  
  <p>I have a HABTM relationship between Users and Core_Values.</p>
  
  <pre><code>class CoreValue &lt; ActiveRecord::Base
    has_and_belongs_to_many :users
  
  class User &lt; ActiveRecord::Base
    has_and_belongs_to_many :core_values
  </code></pre>
  
  <p>In my controller, I need to do two separate things:</p>
  
  <ol>
  <li>If a CoreValue does not exist, create a new one and associate it with a given user id, and</li>
  <li>Assuming I know a particular CoreValue does exist already, create the association without creating any new CoreValues or Users</li>
  </ol>
  
  <p>For # 1, I've got this to work:</p>
  
  <pre><code>User.find(current_user.id).core_values.create({:value =&gt; v, :created_by =&gt; current_user.id})
  </code></pre>
  
  <p>This creates a new CoreValue with :value and :created_by and creates the association.</p>
  
  <p>For # 2, I've tried a few things, but can't quite seem to create the association ONLY.</p>
  
  <p>Thanks for your help!</p>