开发者

Translate SQL statement into named_scope?

开发者 https://www.devze.com 2022-12-29 10:07 出处:网络
How can I translate this SQL into a named_scope? Also, I want the total comments param to be passed through a lambda.

How can I translate this SQL into a named_scope? Also, I want the total comments param to be passed through a lambda.

"select users., count() as total_comments开发者_如何学Go from users, comments where (users.id = comments.user_id) and (comments.public_comment = 1) and (comments.aasm_state = 'posted') and (comments.forum_user_id is null) group by users.id having 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}"
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号