title: Tricky active record relationships - polymorphic bi-directional self-referential
body: <p>How would you model the references and citations to publications (articles, books, chapters, etc...)?</p>
  
  <p>A publication can be an article, book or a chapter and it has many references to other publications and other publications refer to it (call these citations)</p>
  
  <p>I need to be able to list the relationships among the publications: The references in a publication and the citations from other publications to this publication</p>
  
  <p>My initial understanding is that this would be a polymorphic relationship to handle the different types of publications and that it would require a bidirectionalself join.</p>
  
  <p>My stab at it</p>
  
  <pre><code>Publication
  belongs_to :writing, :polymorphic =&gt;true
  has_and_belongs_to_many :references 
     :class_name =&gt; "Publication"
     :join_table =&gt; 'reference_citation' 
     :foreign_key =&gt; 'reference_id'
     :foreign_key =&gt; 'citation_id'
  
  Book,    Chapter,    Article all have:
  has_many :publications :as =&gt;writing
  </code></pre>
  
  <p>I find this a bit confusing so any suggestions that would help clarify it would be great.  Even object and field naming suggestions. </p>
  
  <p>[I asked a less clear version of this question <a href="https://stackoverflow.com/questions/499934/how-would-you-model-articles-with-references-and-citations-in-rails-activerecord">here</a>.] </p>
  
  <p>I also probably need to use has many through because I will need the ability to destroy the relationship</p>