3

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?

jmasterx
  • 52,639
  • 96
  • 311
  • 557

1 Answers1

3

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.

Community
  • 1
  • 1
B Seven
  • 44,484
  • 66
  • 240
  • 385