class Patient < AR::Base has_many :aaas has_many :bbbs ,:through=>:aaas end class Aaa < AR::Base has_many :bbbs end ------- i want like this @patient=Patient.find(id) @new_patient=@patient.duplicate now the @new_patient should have their own copy of patient,aaas,bbbs (new records in corresponding tables) there is one options is that we can create seperate object for each patient,aaas(Array),bbbs(Array) and save them, but if the associations(aaas,bbbs) size(Array.size) are more then it will take too much time i know RAILS framework don''t have any support for this any short ideas or ready mate plugins ? -- Posted via http://www.ruby-forum.com/.
Sniper Abandon wrote:> class Patient < AR::Base > has_many :aaas > has_many :bbbs ,:through=>:aaas > end > class Aaa < AR::Base > has_many :bbbs > end > ------- > i want like this > @patient=Patient.find(id) > @new_patient=@patient.duplicate > > now the > @new_patient should have their own copy of patient,aaas,bbbs (new > records in corresponding tables) >When you said it took too much time, did you test it? Secondly, rails does support this directly through active record.. new_patient = Patient.new(:aaas => @patient.aaas).save! If the aaas and the bbbs have to be deep copied as well, then you can provide your own dup method for them. -- Posted via http://www.ruby-forum.com/.
On Aug 6, 1:03 am, Sniper Abandon <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> class Patient < AR::Base > has_many :aaas > has_many :bbbs ,:through=>:aaas > end > class Aaa < AR::Base > has_many :bbbs > end > ------- > i want like this > @patient=Patient.find(id) > @new_patie...-2G/Efcufjc6xAst9nmAy9bNAH6kLmebB@public.gmane.org > > now the > @new_patient should have their own copy of patient,aaas,bbbs (new > records in corresponding tables) > > there is one options is that > we can create seperate object for each patient,aaas(Array),bbbs(Array) > and save them, but if the associations(aaas,bbbs) size(Array.size) are > more then it will take too much time > > i know RAILS framework don''t have any support for this > > any short ideas or ready mate plugins ?No, but if you find one, the computer science community will be excited. You seem to be asking for a way to copy an array that takes less time than copying the elements. Worrying about speed for something like this is vastly premature optimization... --Matt Jones