我正在研究多态关联问题,但我不太确定该去哪里。
这是我当前的模型设置:
class Rfq < ActiveRecord::Base
attr_accessible :name, :parts_attributes
has_many :parts
accepts_nested_attributes_for :parts
end
class Part < ActiveRecord::Base
attr_accessible :name, :mailer_parts
belongs_to :rfq
belongs_to :partable, :polymorphic => true
has_one :mailer, :through => :partable
accepts_nested_attributes_for :mailer
end
class Mailer < ActiveRecord::Base
attr_accessible :address
has_one :part, :as => :partable # Should/could this be belongs_to?
end
当我在浏览器中转到 Rfq 的编辑页面时,我看到此错误:
ActiveRecord::HasManyThroughAssociationPolymorphicThroughError in Rfqs#edit
Cannot have a has_many :through association 'Part#mailer' which goes through the polymorphic association 'Part#partable'.
Extracted source (around line #5):
2: <%= f.label :name, "Name" %>
3: <%= f.text_field :name %><br>
4: <p>Part Information: </p>
5: <%= f.fields_for :mailer do |builder| %>
6: <%= render 'mailer_fields', :f => builder %>
7: <% end %>
8: <%= link_to 'Add Mailer Part', '#', :class => "add_mailer_part" %>
我不确定问题出在哪里,因为我不想在任何地方建立 has_many 关系。