# Correct use of ":polymorphic =\> true"?

**URL:** <https://www.ruby-forum.com/t/correct-use-of-polymorphic-true/138530>\
**Category:** Rails\
**Created:** [May 24, 2008, 3:06am UTC](https://www.ruby-forum.com/t/correct-use-of-polymorphic-true/138530 "2008-05-24T03:06:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@ldk](https://www.ruby-forum.com/u/ldk)\
**Post date:** [May 24, 2008, 3:06am UTC](https://www.ruby-forum.com/t/correct-use-of-polymorphic-true/138530/1 "2008-05-24T03:06:53Z")

</div>

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?

* * *
