March 22, 2016 by Daniel P. Clark

Rails: Has One Through Polymorphic Relation

As I’ve described in my blog post “Rails Polymorphic Associations” I’ve stated that polymorphic relations in Rails are best for scenarios where a model may “belong to” one of many other kinds of model.  So a Comment model with the polymorphic commentable relationship can belong to any other record in your Rails app.  This is…

Continue Reading »

February 10, 2015 by Daniel P. Clark

Rails Polymorphic Associations

What is a polymorphic association you might ask?  It’s where an ActiveRecord model can potentially belong to more than one other kind of model record.  So the single instance of your car belongs to you, a person, whereas other cars may individually belong to a car lot, a business. Why do we need it? In…

Continue Reading »