Eager Loading with Goldiloader

#30 Eager Loading with Goldiloader
5/23/2016

Summary

Wouldn't it be awesome if ActiveRecord didn't make you think about eager loading and it just did the "right" thing by default? With Goldiloader it can!
0
rails performance model

Summary

Gemfilegem 'goldiloader'

index.html.erb

      <% blog.tags.to_a.map(&:name).each do |tag| %>       <%# blog.tag_list.each do |tag| %>         <div class='badge'>           <%= tag %>         </div>       <% end %>

config/initializers/goldiloader.rbActiveRecord::Associations::Association.default_auto_include = false
# ActiveRecord::Associations::HasManyThroughAssociation.default_auto_include = false
blog.rbclass Blog < ActiveRecord::Base
  acts_as_taggable
  # If you set the initializer file to not auto_include, 
  # you can manually force an auto include
  # has_many :posts, auto_include: true
  
  # Since goldiloader is set to auto_include be default,
  # this behavior can be overridden.
  # has_many :posts, auto_include: false
end