Rails has_many:through:多态关系调用错误

时间:2016-02-22 15:42:07

标签: ruby-on-rails ruby-on-rails-4 activerecord polymorphic-associations

我有has_many:通过:某些模型之间的多态关系:

class Tagging < ActiveRecord::Base
  belongs_to :tag
  belongs_to :tagging, :polymorphic => true
end

class Tag < ActiveRecord::Base
  has_many :taggings
  has_many :recipes,    through: :taggings, source: :taggable, source_type: 'Recipe', dependent: :destroy
end

class Recipe < ActiveRecord::Base
  has_many :taggings, as: :taggable
  has_many :tags, through: :taggings, dependent: :destroy
end

当我输入Tag.first.recipes时出现以下错误:

  

SELECT&#34; tags&#34;。* FROM&#34; tags&#34; ORDER BY&#34;标签&#34;。&#34; id&#34; DESC限制1   ActiveRecord :: HasManyThroughSourceAssociationNotFoundError:无法在模型标记中找到源关联:taggable。尝试'has_many:recipes,:through =&gt; :taggings,:source =&gt; &#39 ;.它是标记还是标记之一?

有什么想法吗?

0 个答案:

没有答案