6

We would like to force our Post model to eager load all comments.

Right now we have to specify the eager loading at the find(:all), like below:

Post.all(:include => [ :comment ])

Is there a way to force an eager loading default at the Post model level, rather than having to do it in every find? Something like below:

class Post < ActiveRecord::Base
  has_many :comments, :include <all comments>  # eager load??
Kevin Baker
  • 1,187
  • 3
  • 12
  • 22

1 Answers1

4

It looks like you'll want to tweak your default_scope for this.

Community
  • 1
  • 1
girasquid
  • 15,121
  • 2
  • 48
  • 58