How to translate this MySQL statement into named_scope method?
"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 ] } }
精彩评论