activerecord-import gem:has_many through issue

时间:2017-02-04 18:20:38

标签: ruby-on-rails ruby-on-rails-4 activerecord activerecord-import

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>

0 个答案:

没有答案