在activerecord-import gem的帮助下,我试图在一个查询中保存包含has_many through
个孩子的记录列表。
我的模特:
class Mailing < ActiveRecord::Base
has_many :mailing_modifications
has_many :modifications, through: :mailing_modifications
end
class Modification < ActiveRecord::Base
has_many :mailing_modifications, dependent: :destroy
has_many :mailings, through: :mailing_modifications
end
class MailingModification < ActiveRecord::Base
belongs_to :mailing
belongs_to :modification
end
我的保存代码:
mailing = Mailing.new
mailing.modifications.build
mailings << mailing
Mailing.import(mailings, recursive: true)
但我收到错误NoMethodError: undefined method modification_id=' for #<Modification:0x00000006eb01d0>