如何将此 SQL 转换为 named_scope?另外,我希望总评论参数通过 lambda 传递。
“选择用户。,计数()作为来自用户的total_comments,其中(users.id = comments.user_id)和(comments.public_comment = 1)和(comments.aasm_state ='posted')和(comments.forum_user_id为空)的评论按 users.id 分组,total_comments > 25"
如何将此 SQL 转换为 named_scope?另外,我希望总评论参数通过 lambda 传递。
“选择用户。,计数()作为来自用户的total_comments,其中(users.id = comments.user_id)和(comments.public_comment = 1)和(comments.aasm_state ='posted')和(comments.forum_user_id为空)的评论按 users.id 分组,total_comments > 25"
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}"
}
}