Closed jim0020 closed 3 years ago
I don't think deep_cloneable would be very useful in your case. I would make a recursive method and use dup
directly instead. Something like this:
class TreeNode < ApplicationRecord
def duplicate
dup.tap { |node| node.children = children.map(&:duplicate) }
end
end
Say I have a TreeNode class: class TreeNode < ApplicationRecord has_many :children, class: :TreeNode, foreign_key: :parent, inverse_of: :parent belongs_to :parent, class: :TreeNode, inverse_of: :children end
how would you deep_clone a given TreeNode object to deep clone the object and all the children, the children's children, etc?