0
class Bar < ActiveRecord::Base
belongs_to :foo
end
class Foo < ActiveRecord::Base
has_many :bars
end
Foo oldFoo = Foo.new
Foo foo = Foo.new
foo.bars << oldFoo.bars.all.collect { |bar| bar.clone }
上述命令不會正確替換bars.foo_id,oldFoo.bars的引用將被刪除並設置爲foo.bars。如何克隆has_many關聯
我該如何正確地做到這一點?