我有这 3 个模型
class User < ActiveRecord::Base
has_many :answers, :as => :owner
end
class Answer < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
has_one :test
end
class Test < ActiveRecord::Base
belongs_to :answer
end
所以我想通过模型将Test
模型与模型关联起来,而不需要在它们之间创建新的关联,所以我将以下内容放入测试模型中:User
Answer
has_one :owner, :through => :answer
但它不起作用,我收到了这个错误
ActiveRecord::HasManyThroughAssociationPolymorphicSourceError: Cannot have a has_many :through association 'Test#owner' on the polymorphic object 'Owner#owner'.
有什么帮助吗?