I need to be able to copy a record. By that I mean that: All the references need to be deep copied.
For example, if I have a Case and it has a patient_id linking to a patient, to copy a case would mean to create a copy of the patient too.
Therefore, what would be a 'best practices' way to do this. My first thought was to make a create_copy method for all my models and each of these calls that for all their dependencies to create a cascading deep copy.
I am just wondering if there is a more 'rails' way to do this where I could add on to the clone function?
You may want to give the Amoeba gem a try.
Reference: https://stackoverflow.com/a/9485672/336920
Also deep_clonable.
They both work with Rails 4 and have been updated recently.
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