帮助重构named_scope

时间:2010-07-09 23:09:40

标签: ruby-on-rails named-scope

我有以下named_scope:

  named_scope :commentors, lambda { |*args|
      { :select => 'users.*, count(*) as total_comments',
        :joins => :comments,
        :conditions => { :comments => { :public_comment => 1, :aasm_state => 'posted', :chalkboard_user_id => nil} },
        :group => 'users.id',
        :having => ['count(*) > ?', args.first || 0],
        :order => 'count(*) desc' }
      } 

我需要将条件重构为以下内容:

["(public_comment = ? and box IS NOT NULL and can IS NOT NULL and aasm_state != ?", true, 'removed')]

我没有太多运气改变条件的语法。有人可以得到善意的帮助吗?

1 个答案:

答案 0 :(得分:0)

看起来您只需要将表名称赋予字段即可。我不确定哪个表boxcan属于哪个,但这应该会给你一个想法:

["comments.public_comment = ? and box IS NOT NULL and can IS NOT NULL and comments.aasm_state != ?", true, 'removed')]

你在开头我也有一个左括号。