0

I am using the Amoeba gem to clone a model and all children. The gem is working well with one exception - there is one :has_many association that is not being picked up.

My parent Model is Option:

class Option < ActiveRecord::Base

has_many :products, as: :productable, dependent: :destroy
has_many :censusinfos, :autosave => true

belongs_to :rating

accepts_nested_attributes_for :censusinfos


amoeba do
  enable
end

# other code.....

Products is being cloned appropriately, but the issue is on :censusinfos. That model is defined as:

class Censusinfo < ActiveRecord::Base

has_many :census_sheets
has_many :census_fields
belongs_to :option

#other code......

CensusField children are copied correctly, but CensusSheet is not being cloned.

Any thoughts/ideas why??

Thanks!

Greg

Gpcnec76
  • 69
  • 1
  • 8

2 Answers2

1

I read the documentation at the following link

ActiveRecord: How can I clone nested associations?

Should't you enable recursive copying of associations by including in class Censusinfo amoeba do enable end?

class Censusinfo < ActiveRecord::Base

has_many :census_sheets
has_many :census_fields
belongs_to :option

amoeba do
  enable
end

Thanks

Fabrizio

Community
  • 1
  • 1
Fabrizio Bertoglio
  • 5,890
  • 4
  • 16
  • 57
0

I needed to add "enable" to Censusinfo. Example below. Thanks to Fabrizio!

class Censusinfo < ActiveRecord::Base

has_many :census_sheets
has_many :census_fields
belongs_to :option

amoeba do
  enable
end

#other code...... 
Gpcnec76
  • 69
  • 1
  • 8