0

次の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')]

条件を変更するための構文にあまり運がありません。誰かが親切に助けてくれますか?

4

1 に答える 1

0

フィールドにテーブル名を付けるだけでよいようです。がどのテーブルboxcan属しているかはわかりませんが、これでアイデアが得られるはずです。

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

また、最初に開いた括弧がありましたが、これを削除しました。

于 2010-07-10T00:07:18.177 に答える