# Single Table Inheritance VS Polymorphic Associations

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-vs-polymorphic-associations/92922>\
**Category:** Rails\
**Created:** [April 25, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-vs-polymorphic-associations/92922 "2007-04-25T18:20:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesselfout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7cd45c/32.png) [@jesselfout](https://www.ruby-forum.com/u/jesselfout)\
**Post date:** [April 25, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-vs-polymorphic-associations/92922/1 "2007-04-25T18:20:37Z")

</div>

I am trying to evaluate the reuse of software between versions.

With out going into how I’m doing this i have a style question:

If I have model Artifact, which right now can be typed as SrcCode or  
Document  
and basically is a file on the system right now I’m doing this by  
polymorphic associations  
which works well for the Artifact class

I need to create ReusedArtifact(s) which is a composite of two  
artifacts,  
and illustrates the differences between the two artifacts. The  
problem  
is in order to use polymorphic associations I need to save the base  
object (ReusedArtifact) before I can create and use it’s sub class  
(ReusedSourceCodeArtifact or ReusedDocumentation) methods…

We have these fields for the two types:  
DOC: (words)  
wdiff\_added  
wdiff\_common  
wdiff\_changed  
wdiff\_delete  
SRC: (lines)  
diff\_added  
diff\_common  
diff\_changed  
diff\_delete

Personally I think that a single table inheritance setup, with  
added,common,changed and deleted as the fields  
would work well. On the other hand can anyone forsee a design problem  
that could be caused by counting  
and storing two different things (words and lines) in the same  
fields…

Thanks  
JEsse
