[Rails] Deep Copy Method?
Thomas Counsell
tamc2 at cam.ac.uk
Tue Jan 4 08:59:29 GMT 2005
Sorry, just to clarify,
I guess I'm really trying to duplicate a set of rows in various
database tables, to which the Rails ActiveRecord objects point.
I suspect (will check later) that Marshal.load Marshal.dump( self )
will just create a duplicate set of objects without duplicating the
underlying table rows? or are Active Record objects cleverer than that?
Apologies for not being clear in my original post.
----
Tom Counsell. http://tom.counsell.org
On 4 Jan 2005, at 00:20, Eric Hodel wrote:
> On 03 Jan 2005, at 12:44, Thomas Counsell wrote:
>
>> Have you got a / can you help with a generic method for doing a deep
>> copy of a set of Rails objects?
>>
>> I see there is a clone method for individual objects.
>>
>> I can also see it would be pretty easy to implement a method that
>> copies down a tree.
>>
>> The tricky bit is how to deep copy where objects within the tree
>> reference each other?
>>
>> Thanks for any tips.
>
> class Object
> def deep_clone
> Marshal.load Marshal.dump(self)
> end
> end
More information about the Rails
mailing list