开发者

How to translate this MySQL statement into named_scope method?

开发者 https://www.devze.com 2022-12-24 00:59 出处:网络
\"select * from users, awards where (users.id = awards.use开发者_如何学JAVAr_id) and awards.trophy_id not in (select awards.trophy_id from awards where awards.trophy_id = #{trophy.id})\"Answered own q

"select * from users, awards where (users.id = awards.use开发者_如何学JAVAr_id) and awards.trophy_id not in (select awards.trophy_id from awards where awards.trophy_id = #{trophy.id})"


Answered own question:

named_scope :not_awarded_trophy, lambda { |trophy| { :include => :awards, :conditions => [ "awards.trophy_id not in (select awards.trophy_id from awards where awards.trophy_id = ?)", trophy.id ] } }

0

精彩评论

暂无评论...
验证码 换一张
取 消