amoeba-rb/amoeba

Child records not getting updated with proper reference Id.

Opened this issue · 0 comments

Hi All,
I have the following models

  class Bmc < ActiveRecord::Base
     has_many :segments
     has_many :value_propositions
     has_many :relationships
     amoeba do
        enable
     end
  end

  class Segment < ActiveRecord::Base
    has_one :value_proposition
    has_and_belongs_to_many :relationships
    amoeba do
       recognize [:has_one, :has_and_belongs_to_many]
    end
  end

  class ValueProposition < ActiveRecord::Base
    belongs_to :bmc
   belongs_to :segment
    amoeba do
       recognize :belongs_to
    end
  end

  class Relationship < ActiveRecord::Base
    belongs_to :bmc
    has_and_belongs_to_many :segments
    amoeba do
       recognize :has_and_belongs_to_many
    end
  end

In my controller I'm doing

 bmc_copy =  Bmc.find(id).amoeba_dup
 bmc_copy.save.

I wanted to duplicate the records recursively when I dup the bmc. But for some reason segment_id(s) not getting updated properly in relationship and value_proposition tables, when i save the bmc_copy(original segment id(s) is getting copied as-is and not the duplicated sendment's id).

Can someone help me where am I doing wrong?