With polymorphic associations, one class can belong_to more than one type of another class. In other words, this is not polymorphism in the typical object-oriented sense of the word; rather, it is something unique to Rails.
In the Case of Models with Comments
For example, you might have a Comment
model that belongs to either Timesheet
model or BillableWeek
model.
Here is a migration that will create the comments
table:
1 | class CreateComments < ActiveRecord::Migration |
Here is Comment
, Timesheet
and BillableWeek
models:
1 | class Comment < ActiveRecord::Base |
Has_many :through and Polymorphics
1 | class Comment < ActiveRecord::Base |