1

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>

4

0 回答 0