How would you model the references and citations to publications (articles, books, chapters, etc…)?
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)
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
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.
My stab at it
Publication belongs_to :writing, :polymorphic =>true has_and_belongs_to_many :references :class_name => 'Publication' :join_table => 'reference_citation' :foreign_key => 'reference_id' :foreign_key => 'citation_id' Book, Chapter, Article all have: has_many :publications :as =>writing
I find this a bit confusing so any suggestions that would help clarify it would be great. Even object and field naming suggestions.
[I asked a less clear version of this question here.]
I also probably need to use has many through because I will need the ability to destroy the relationship
Here’s a solution using a self-referential relationship using single table inheritance. Use these commands to create the app:
The setup the relationships this way:
Now we can create the DB and try it out from the console: