I'm in the process of familiarizing myself with both RoR and database design, which has me seeking some resurance (or tips for change) on my current problem.
I'm creating a list of journal articles, books and book chapters. Each article, book and chapter has many authors.
Models and their columns (not the actual code): model: Journal name, abbreviated_name, url model: AuthorInfo last_name, first_name, middle_name,
model: Author author_info_id, authored_id, authored_type
model: Book name, edition, publisher, year model: Article title, year, journal_id, volume, issue model: Chapter title, book_id
The relationships are as follows:
class Journal < ActiveRecord::Base has_many => :articles end
class AuthorInfo < ActiveRecord::Base has_many => authors end
class Author < ActiveRecord::Base belongs_to => :authored, :polymorphic => true belongs_to => :authorinfo end
class Book < ActiveRecord::Base has_many => :chapters has_many => :authors, :as => :authored end class Article < ActiveRecord::Base belongs_to => :journal has_many => :authors, :as => :authored end class Chapter < ActiveRecord::Base belongs_to => :book has_many => :authors, :as => :authored end
Example for journal article: Title: "Neuroplasticity and the frontal lobes", authors: J Kilman, T Spence, Z Atoms. Journal: Neuron
This would hopefully be associated with: one row in the Articles table, 3 rows in the Authors table (one for each author), 1 row in the Journal table. Each author would have one row on the AuthorInfos table.
Does this make sense, is there a better way to do this?