Eager Loading Polymorphic Associations in Ruby on Rails

For when .includes is not enough.

Photo by Paul Smith on Unsplash

Basic Rails Associations

Rails’ ActiveRecord associations permits relating one model to another. Take the example below:

class Post < ApplicationRecord
has_many :comments
end
class Comment < ApplicationRecord
belongs_to :post
end