如何将这个MySQL语句翻译成named_scope方法?

时间:2010-03-19 14:56:54

标签: sql ruby-on-rails ruby named-scope

“select * from users,awards where(users.id = awards.user_id)和awards.trophy_id not in(select awards.trophy_id from awards awards awards.trophy_id =#{trophy.id})”

1 个答案:

答案 0 :(得分:0)

回答了自己的问题:

named_scope:not_awarded_trophy,lambda {| trophy |     {:include => :awards,:conditions => [“awards.trophy_id不在(选择awards.trophy_id来自奖项,其中awards.trophy_id =?)”,“trophy.id”}   }