我有用户,游戏和GameView。 GameView描述了用户看到的游戏。麻烦是我无法弄清楚我应该使用什么条件来获取未观看的游戏。has_many“不是”:通过。我应该使用什么条件?
class User < ActiveRecord::Base
has_many :game_views
has_many :unviewed_games, :through => :game_views, :source => :game, ???what conditions???
end
class GameView < ActiveRecord::Base
belongs_to :user
belongs_to :game
end
+1。不需要在查询中添加':include'子句。我也会删除声明检查行,即'@unviewed_games || = Game.all(...' – 2010-07-21 07:05:07
关于':include'的好声音,我在写邮件时改变了查询。 ,只是因为'|| ='仍然可以重新查询数据库,如果一个零返回 - 不应该发生在'.all'上,但我喜欢我的代码是一致的。这样我总是有声明检查而不是有时'|| ='有时候还有一个声明检查。 – 2010-07-21 15:46:44