在Rails中预加载与范围和参数的关联

时间:2016-06-24 15:06:38

标签: ruby-on-rails postgresql ruby-on-rails-4 activerecord rails-activerecord

假设我们有这样的事情:

class Group < ActiveRecord::Base
  has_many :users
end

class User < ActiveRecord::Base
  scope :have_more_than_X_posts, -> (x) { where('posts_count > ?', x) }
end

我希望能够拨打以下内容:Group.includes(users: {have_more_than_X_posts: 10})

想法?

0 个答案:

没有答案