Access denied, Please sign in and make sure you have proper permission.
  • 不要把查询方法(比如 where) 放到 ActiveRecord::Base 类里的某个实例方法中。这个可能不太明显,来看个示例:

    class Post < ActiveRecord::Base belongs_to :post

    def latest_comment comments.order('published_at desc').first end


    这个要怎么改,才能避免 N+1