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 <rails-mailing-l...@andreas-s.net> wrote: > 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| > @clone.my_items.build(item.clone) > end > > 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. > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---