Search code examples
ruby-on-railsrubyamoeba-gem

amoeba not cloning all :has_many associations


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


Solution

  • 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