title: Model a person-to-person relationship in Ruby-on-Rails using has_many :through
body: <p>I would like to model a person's relationship to another person, where the relationship isn't necessarily hierarchical (i.e. friends &amp; colleagues, rather than parent &amp; children) and I am interested in capturing more detail about each relationship (e.g. notes, type of relationship, date established). Finally, I would like to use the act_as_tree relationship to be able to navigate/diagram these relationships.</p>
  
  <p>The migrations:</p>
  
  <pre><code>class CreateProfiles &lt; ActiveRecord::Migration   def self.up
      create_table :profiles do |table|
        table.column :firstName, :string
        table.column :lastName, :string
        table.column :telephone, :string
        table.column :emailAddress, :string
        table.column :location, :string
        table.timestamps
      end   end   def self.down
      drop_table :profiles   end end
  
  class Relationship &lt; ActiveRecord::Migration   def self.up
      create_table :relationships, :id =&gt; false do |table|
        table.column my_id :integer
        table.column your_id :integer
        table.column relationshipType :string
        table.column dateEstablished :date
        table.column notes :text
        table.timestamps      end   end   def self.down
      drop_table :relationships   end end
  </code></pre>
  
  <p>The models:</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    has_many :relationships, :foreign_key =&gt; "my_id"
    has_many :persons :through =&gt; :relationships
  end
  
  class Relationship &lt; ActiveRecord::Base
    belongs_to :persons
    acts_as_tree
  end
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>How do I define the relationships between these tables correctly?</li>
  <li>As the my_id/your_id combination is unique, does it make sense to eliminate the :id on the relationships table?</li>
  <li>Are there better names for the 'my_id' &amp; 'your_id' fields to make use of RoR's conventions?</li>
  <li>Will I have difficulties with the act_as_tree relationship if one of the columns isn't name 'parent_id'?</li>
  </ol>