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

Association issue when cloning an object #52

Closed KranthiKishore closed 8 years ago

KranthiKishore commented 9 years ago

Hi,

I'm facing an issue when cloning an object and its associations which is explained here http://stackoverflow.com/questions/32633130/deep-clonable-associated-records-validation-issue.

Can someone help me

moiristo commented 9 years ago

There are validation errors on the associations, so you should check what's wrong there:

copy.relationships.map{|rs| rs.errors.full_messages }
KranthiKishore commented 9 years ago

copy.relationships.map{|rs| rs.errors.full_messages } => [["Customer segments can't be blank"]] This is the error am getting. Which means customer_segment should be created before my relationship is getting created. Any way is there to handle this situation?

moiristo commented 9 years ago

You should include those associations as well and if needed you should use a dictionary: https://github.com/moiristo/deep_cloneable#the-dictionary-object-reusage. You can also do it manually after the clone has been created.