如何将此 SQL 转换为named_scope?另外,我希望总评论参数通过 lambda 传递。
“选择用户。,计数()作为用户的总评论数,其中(users.id = comments.user_id)和(comments.public_comment = 1)和(comments.aasm_state = '发布') 和 (comments.forum_user_id 为空) 按总评论数 > 25 的 users.id 进行分组"
最佳答案
named_scope :comments_count_gt, lambda { |count|
{ :select => "users., count() as total_comments",
:joins => :comments,
:conditions => { :comments => { :public_comment => 1, :aasm_state => 'posted' } },
:group => "users.id",
:having => "total_comments > #{count.to_i}"
}
}
关于sql - 将SQL语句翻译成named_scope?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2795616/