title: Symmetrical, self-referential HABTM relationship
body: <p><br/>
  In my schema I have a model called Imprintables. In this model I have this self-referential relationship:
  </p>
  
  <pre><code>class Imprintable &lt; ActiveRecord::Base
    has_and_belongs_to_many :coordinates, class_name: 'Imprintable', association_foreign_key: 'coordinate_id', join_table: 'coordinates_imprintables'
  ...
  end
  </code></pre>
  
  <p>In the imprintable create/edit form I have a select field where users can select coordinate imprintables (coordinates are used to identify imprintables that are similar to the one being created/edited). My issue is that if I have an imprintable A and and imprintable B, when I create A and list B as a coordinate imprintable, I want to be able to look at the edit form for B and see A also listed as a coordinate.</p>
  
  <p>I've tried modifying the controller's update and create action to insert both pairs of id's into the linker table (coordinates_imprintables). For instance if A.id = 1 and B.id = 2, then executing some sql like: 
  </p>
  
  <pre><code>INSERT INTO coordinates_imprintables (imprintable_id, coordinate_id) VALUES (1, 2)
  INSERT INTO coordinates_imprintables (imprintable_id, coordinate_id) VALUES (2, 1)
  </code></pre>
  
  <p>But I couldn't get it working because I'm not sure how to know when a user is trying to delete or insert a coordinate, and I'm not even sure if that's the correct answer anyway. Railscasts have been marginally helpful, this just seems like a tricky case because I have a model with a self-referential relationship that is also symmetrical. Thanks for you time!</p>