Reputation: 1197
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??
Upvotes: 6
Views: 1957
Reputation: 15526
It looks like you'll want to tweak your default_scope for this.
Upvotes: 4