title: ActiveRecord relationships for a join table linking two records of the same table?
body: <p>I have a Character model and a Link model. The Link model represents a link from a character to another character. A link has a textual 'description' attribute. A link from character A to character B is distinct from the opposite link from B to A. A character has zero or one link to another character. A character may have various links to different characters. A character may be linked to by various different characters.</p>
  
  <p>I used used Active Record relationships to partly implement relationships between Character and Link models:</p>
  
  <pre><code>class Character 
   has_many :links # the links from the character to other characters
  
  class Link 
   belongs_to :character # the character from which starts the link to another character
  </code></pre>
  
  <p>which give me useful methods like character.links (array of all links starting from this character) or link.character (character from which starts the link)</p>
  
  <p>The link model has also a <code>to_character_id</code> which contains the id of the character to who goes the link. Thus a link from character A to character B is an instance with the following attributes:  </p>
  
  <ul>
  <li><code>character_id</code> = id of character A  </li>
  <li><code>to_character_id</code> = id of character B  </li>
  <li><code>description</code> = some text</li>
  </ul>
  
  <p>I've written various extra methods like <code>character.links_to</code> (returning an array of all links which points to the character) or <code>link.to_character</code> (returning the character to which points the link), or <code>character.characters_who_link_to</code> (returning an array of the other characters having a link to this character). I've written also a callback to make sure that when a character is deleted, all links which go to this character are deleted (same for restoration).</p>
  
  <p>Is possible to use additional AR relationships declarations which would provide me with this kind of extra methods, so that I do not have to write myself those methods and callbacks?  </p>
  
  <p>Agile Web Development with Rails presents a solution in the section "Using Models as Join Tables" but for a join table joining two different tables.
  In my case my join table Links join records of a single table, Characters.</p>