在我的应用程序中,我有 User、Video 和 Vote 类。用户和视频可以通过两种不同的方式相互关联:一对多或多对多。前者是用户提交视频时(一个用户可以提交多个视频)。后者是当用户对视频进行投票时(用户通过投票拥有许多视频,反之亦然)。这是我的代码,它不起作用(我认为 - 我可能在视图中做错了什么)。请帮助我理解构建这些关联的正确方法:
class User < ActiveRecord::Base
has_many :videos, :as => :submissions
has_many :votes #have tried it without this
has_many :videos, :as => :likes, :through => :votes
end
class Vote < ActiveRecord::Base
belongs_to :video
belongs_to :user
end
class Video < ActiveRecord::Base
belongs_to :user
has_many :votes #have tried it without this . . . superfluous?
has_many :users, :as => :voters, :through => :votes
end