@duplicate = @budget.deep_clone include: :budget_items, except: [:slug, :comments_count, :uploads_count ] do |original, duplicate|
duplicate.name = "#{original.name} Copy"
end
The expected action is that the budget.name has Copy appended. The issue is that my budget_items model also has a name attribute and when deep cloned those associated records get modified also.
This is documented behavior, please see the note in the Optional Block section. You should check the type of the object in the block: duplicate.name = "#{original.name} Copy" if original.is_a?(Budget)
Here is my deep clone code:
The expected action is that the
budget.name
has Copy appended. The issue is that mybudget_items
model also has a name attribute and when deep cloned those associated records get modified also.