Duplicate model object with associations?

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)
@[email protected]

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 ?

Sniper A. 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)
@[email protected]

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.

On Aug 6, 1:03 am, Sniper A. [email protected]
wrote:

@removed_email_address@domain.invalid
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 J.