Rails Eager Loading on All Finds

前端 未结 2 1147
太阳男子
太阳男子 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条回答
  • 2020-12-13 05:27

    You should be able to do this with named scopes, but I understand that there were a number of possible bugs with that, hopefully they are all fixed now.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题