# How to make a deep copy of ActiveRecord

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-deep-copy-of-activerecord/110419>\
**Category:** Rails\
**Created:** [July 26, 2007, 6:23am UTC](https://www.ruby-forum.com/t/how-to-make-a-deep-copy-of-activerecord/110419 "2007-07-26T06:23:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaoxt1983](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@gaoxt1983](https://www.ruby-forum.com/u/gaoxt1983)\
**Post date:** [July 26, 2007, 6:23am UTC](https://www.ruby-forum.com/t/how-to-make-a-deep-copy-of-activerecord/110419/1 "2007-07-26T06:23:50Z")

</div>

I wanna make a method that can deep copy an ActiveRecord to a new one,  
but it seems a little difficult , how to do it?

---

<div class="post-metadata">

**Author:** ![gaoxt1983](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@gaoxt1983](https://www.ruby-forum.com/u/gaoxt1983)\
**Post date:** [July 26, 2007, 6:53am UTC](https://www.ruby-forum.com/t/how-to-make-a-deep-copy-of-activerecord/110419/2 "2007-07-26T06:53:52Z")

</div>

On 7/26/07, gaoxt1983 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I wanna make a method that can deep copy an ActiveRecord to a new one,  
> but it seems a little difficult , how to do it?
> 
> >

Marshal::load(Marshal::dump(object))

Gustav P.

---

<div class="post-metadata">

**Author:** ![gaoxt1983](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b4bc9f/32.png) [@gaoxt1983](https://www.ruby-forum.com/u/gaoxt1983)\
**Post date:** [May 19, 2011, 2:12pm UTC](https://www.ruby-forum.com/t/how-to-make-a-deep-copy-of-activerecord/110419/3 "2011-05-19T14:12:51Z")

</div>

I think the question’s more about creating a new record that has all of  
the relationships?

All the Marshal trick does is create an identical copy.
