如何解决MySQL错误?链接命名范围
我正在尝试在我的用户模型中链接两个named_scope。
第一个:
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`...
如何解决此问题?
I'm trying to chain two named_scopes in my User model.
The first:
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' }
}
The second:
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 ]
}
}
I am trying to chain the two like this:
User.commentors(25).not_awarded_badge(1)
However, I get the following error:
Mysql::Error: Unknown column 'total_comments' in 'order clause': SELECT `users`.`id`...
How can I resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改变
它
应该喜欢
change
to
it should like