# Cloning ActiveRecord objects

**URL:** <https://www.ruby-forum.com/t/cloning-activerecord-objects/157006>\
**Category:** Rails\
**Created:** [January 6, 2009, 12:45pm UTC](https://www.ruby-forum.com/t/cloning-activerecord-objects/157006 "2009-01-06T12:45:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [January 6, 2009, 12:45pm UTC](https://www.ruby-forum.com/t/cloning-activerecord-objects/157006/1 "2009-01-06T12:45:25Z")

</div>

Hi there,

I’ve been working on a solution to try and fix a problem I am getting  
with the Interlock plugin. However, my quick solution was to clone my  
ActiveRecord object and store the clone. I now realise that cloning  
ActiveRecord objects merely extracts the attributes and creates a new  
object with the same attributes. What I want is to clone the whole  
object, in this case assocations aren’t necessary just the object with  
the correct id.

Is there any reason why this would be bad? I guess cloning the object is  
generally used to duplicate records but here I want to take the object  
and cache it without affecting the original object.

RobL

---

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [January 6, 2009, 2:47pm UTC](https://www.ruby-forum.com/t/cloning-activerecord-objects/157006/2 "2009-01-06T14:47:06Z")

</div>

Try your\_active\_record\_instance.dup instead of .clone.
