我试图在我的用户模型中链接两个 named_scopes。
首先:
named_scope :commentors, lambda { |*args|
{ :select => 'users.*, count(*) as total_comments',
:joins => :comments,
:conditions => { :comments => { :public_comment => 1, :aasm_state => 'posted', :talkboard_user_id => nil} },
:group => 'users.id',
:having => ['total_comments > ?', args.first || 0],
:order => 'total_comments desc' }
}
第二:
named_scope :not_awarded_badge, lambda { |badge_id|
{ :include => :awards,
:conditions => [ "? not in (select awards.badge_id from awards where awards.user_id = users.id)", badge_id ]
}
}
我正在尝试像这样链接两者:
User.commentors(25).not_awarded_badge(1)
但是,我收到以下错误:
Mysql::Error: Unknown column 'total_comments' in 'order clause': SELECT `users`.`id`...
我该如何解决这个问题?