# Polymorphic has\_many :through Vs Inheritance

**URL:** <https://www.ruby-forum.com/t/polymorphic-has-many-through-vs-inheritance/123737>\
**Category:** Rails\
**Created:** [December 20, 2007, 7:36am UTC](https://www.ruby-forum.com/t/polymorphic-has-many-through-vs-inheritance/123737 "2007-12-20T07:36:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [December 20, 2007, 7:36am UTC](https://www.ruby-forum.com/t/polymorphic-has-many-through-vs-inheritance/123737/1 "2007-12-20T07:36:38Z")

</div>

Hi everyone.  
Ive part of a project that I need to refactor, and im having some  
difficultly deciding which path to take. Perhaps someone can help, I  
think its primarily a design question.

A Spec consists of many Nests and many Parts. Nests contain Parts.

## Here’s what I have, which works well currently:

class Spec \<\< ActiveRecord::Base  
has\_many :parts, :through =\> :speclines  
has\_many :nests, :through =\> :speclines  
end

class Specline \<\< ActiveRecord::Base  
belongs\_to :spec  
belongs\_to :part  
belongs\_to :nest  
end

class Part \<\< ActiveRecord::Base  
has\_many :specs, :through =\> :speclines  
end

## class Nest \<\< ActiveRecord::Base has\_many :specs, :through =\> :speclines end

Now the question is, how do I simplfy this?

Option 1 is polymorphic associations. But do they work with has\_many  
:through?

Or, seeing that nests and parts are similar, should I make them children  
of a parent class that I then have the association on that? What would  
that look like?

Any help would be appriciated.

-Dave
