moiristo / deep_cloneable

This gem gives every ActiveRecord::Base object the possibility to do a deep clone that includes user specified associations.
MIT License
785 stars 89 forks source link

validate: false for included records #100

Closed varg90 closed 5 years ago

varg90 commented 6 years ago

Hi! I have a huge include: statement in my .deep_clone options and I use validate: false to speed up the cloning process (it takes a days to finish). But when I tried to debug the cloning process, I noticed that it still uses validations. In the gem files it says

Force :validate => false on all saves.

I have to manually skip each of my validation before to run cloned_record.save! and now it takes just a few seconds to finish. Not sure, why validate: false was ignored, if I understand it right, it should be used in this part of code

if options[:validate] == false
  kopy.instance_eval do
    # Force :validate => false on all saves.
    def perform_validations(options={})
      options[:validate] = false
      super(options)
    end
  end
end
moiristo commented 6 years ago

Hi! There are also some tests for it, so I'm not sure yet why it shouldn't work. Which version of rails are you using?

varg90 commented 6 years ago

Hey! I use deep_cloneable v2.3.2 for my rails (v5.1.4) project

varg90 commented 6 years ago

Skipping validations in Rails is a bit of pain if you need to skip them recursive (validate: false works only for the main record on save), so I think this option is very useful

moiristo commented 6 years ago

Yeah, when I have some time I hope I can create a test that reproduces the issue.

moiristo commented 5 years ago

Will be fixed in v3 (now in master)