How to force load active record (Ruby) at model level?

We would like to get our Post model to load all comments.

Right now, we must specify the desired load in find (: all), as shown below:

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

Is there a way to make loading load by default at the Post model level, instead of doing it in every find? Something like below:

 class Post < ActiveRecord::Base has_many :comments, :include <all comments> # eager load?? 
+6
ruby-on-rails activerecord eager-loading
source share
1 answer

It looks like you will want to configure your default_scope for this.

+4
source share

All Articles