[Rails] Deep Copy Method?
Tobias Luetke
tobias.luetke at gmail.com
Tue Jan 4 09:03:06 GMT 2005
try @model.dup.save or Model.create( @model.attributes )
On Tue, 4 Jan 2005 08:59:29 +0000, Thomas Counsell <tamc2 at cam.ac.uk> wrote:
> 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
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Tobi
http://www.hieraki.org - Open source book authoring
http://blog.leetsoft.com - Technical weblog
More information about the Rails
mailing list