2

I am duplicating a rails object, it is duplicating fine with all details except the created_at value of the object. I am using deep_clone gem for doing deep duplication .

Here is the code . I want created_at value of raw_materials and costing_items .

@costing = @old_costing.deep_clone :include => [{style: :images}, {raw_materials: :costing_items} , :other_cost_fixeds, :other_costs, :exchange_rates ], :use_dictionary => true do |original, kopy|
                kopy.remote_picture_url = original.picture_url if kopy.is_a?(Image)
            end
Dev R
  • 1,892
  • 1
  • 25
  • 38

1 Answers1

0

It seems it is simple to do with deep_clone and can be done in the do block so if we do

@costing = @old_costing.deep_clone :include => [{style: :images}, {raw_materials: :costing_items} , :other_cost_fixeds, :other_costs, :exchange_rates ], :use_dictionary => true do |original, kopy|
                kopy.remote_picture_url = original.picture_url if kopy.is_a?(Image)
kopy.created_at = original.created_at
            end

then it will add created_at on all the nested attributes .

Got this answer from this post https://github.com/moiristo/deep_cloneable/issues/54

Dev R
  • 1,892
  • 1
  • 25
  • 38