Forum: Ruby on Rails AR deep clone

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-01-06 19:25
Hi all,

I'm having problems with cloning an ActiveRecord Object. The object
consists of multiple child objects, so when I use the normal clone
method, it only clones the attributes of the parent object.

Could someone help me out telling me how I can clone the child objects
as wel? I have tried like:

      tmp.my_items.each do |item|

but that didn't help. I know it must be something fairly easy, but I
can't figure it out.

Thank you in advance for the help.
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-01-06 23:05
(Received via mailing list)
Ran into this a while back.

your_ar_instance.dup will keep the child records as well.

On Jan 6, 1:25 pm, Michael Rigart <>
This topic is locked and can not be replied to.