Eager Loading Polymorphic Associations in Ruby on Rails

Paulo Carvalho
3 min readOct 27, 2020

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

--

--

Paulo Carvalho

Want to chat about startups, consulting or engineering? Just send me an email on paulo@avantsoft.com.br.