views:

23

answers:

1

I have the following 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' }
      } 

I need to refactor the condition to the following:

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

I'm not having much luck with the syntax to change the condition. Can someone be of kind assistance?

A: 

It looks like you just need to give the table name to the fields. I am not sure which table box and can belong to but this should give you an idea:

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

You also had an open parenthesis at the beginning which I removed.

Geoff Lanotte