Ruby on rails 3 使用through的泛型多对多多态关联?

Ruby on rails 3 使用through的泛型多对多多态关联?,ruby-on-rails-3,activerecord,many-to-many,polymorphism,Ruby On Rails 3,Activerecord,Many To Many,Polymorphism,在问这个问题之前,我必须说,我确实在网上搜索过,试图找到答案,但我没有找到任何解决我问题的方法。没有解决我的问题,因为我不想指定源代码类型,我想要一个通用的东西-你会理解的 好的,我们走吧。我在我的项目中使用了“多对多多态”关系,但我无法让它工作。在尝试使用多态性之前,这只是一个“多对多”关系,工作得非常好,所以我想保持结构,只是添加多态性 结构: 多对多:一个用户和访问者有许多主题,反之亦然。我们假设用户和访问者是追随者,主题被跟随 关系表:此对象有一个名为“psrelations”(人员-主

在问这个问题之前,我必须说,我确实在网上搜索过,试图找到答案,但我没有找到任何解决我问题的方法。没有解决我的问题,因为我不想指定
源代码类型
,我想要一个通用的东西-你会理解的

好的,我们走吧。我在我的项目中使用了“多对多多态”关系,但我无法让它工作。在尝试使用多态性之前,这只是一个“多对多”关系,工作得非常好,所以我想保持结构,只是添加多态性

结构: 多对多:一个
用户
访问者
有许多
主题
,反之亦然。我们假设
用户
访问者
追随者
主题
跟随


关系表:此对象有一个名为“psrelations”(人员-主题关系)的关系表。此表存储多对多关系。


模型: psrelations.rb:

attr_accessible :followed_id, :follower_type, :follower_id
belongs_to :follower, polymorphic: true 
belongs_to :followed, class_name: "Subject"
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
user.rb:

attr_accessible :followed_id, :follower_type, :follower_id
belongs_to :follower, polymorphic: true 
belongs_to :followed, class_name: "Subject"
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
visitor.rb:

attr_accessible :followed_id, :follower_type, :follower_id
belongs_to :follower, polymorphic: true 
belongs_to :followed, class_name: "Subject"
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
has_many :psrelations, as: :follower, dependent: :destroy  
has_many :followed_subjects, through: :psrelations, source: :followed
subject.rb

has_many :psrelations, as: :followed, dependent: :destroy
has_many :followers, through: :psrelations, source: :follower

我希望“followers”返回所有“访问者”和“用户”,而不仅仅是一个或另一个,比如指定源类型

看起来一切正常,但当我尝试
自我关注。包括?(person)
(person可以是用户或访问者)时,我得到了:

我做错了什么