How do i and is it possible clone records and it's associated records?
Example.
Category
_| Product
___| Product variant
So, when i click a button, the category, products and product variants is cloned/copied.
Thanks...
You must overwrite #clone so that all associations are also cloned, like
class Category < ActiveRecord::Base
has_many :products
alias_method :original_clone, clone
def clone
category = self.original_clone
category.products = self.products.clone
end
end
... remember to do the same on Product and ProductVariant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With