Rails Eager Loading on All Finds

前端 未结 2 1158
太阳男子
太阳男子 2020-12-13 04:44

OK, I\'ve been playing around with some of the eager loading things, and have 2 models something like:

Class Recipe < ActiveRecord::Base
    belongs_to :c         


        
2条回答
  •  -上瘾入骨i
    2020-12-13 05:36

    I've been using default_scope to do it on selected models where I always want to eager load:

    class Post < ActiveRecord::Base
      has_many :comments
      default_scope :include => :comments, :order => ["title ASC"]
      ...
    end
    

提交回复
热议问题