Polymorphic has_many :through Vs Inheritance

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

class Specline << ActiveRecord::Base
belongs_to :spec
belongs_to :part
belongs_to :nest

class Part << ActiveRecord::Base
has_many :specs, :through => :speclines

class Nest << ActiveRecord::Base
has_many :specs, :through => :speclines

Now the question is, how do I simplfy this?

Option 1 is polymorphic associations. But do they work with has_many

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.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs