lib/mongoid/relations/referenced/batch.rb in mongoid-2.3.5 vs lib/mongoid/relations/referenced/batch.rb in mongoid-2.4.0

- old
+ new

@@ -36,14 +36,15 @@ # # @return [ Object ] The result of the operation. # # @since 2.0.2, batch-relational-insert def batched(&block) - inserter = Threaded.insert ||= Insert.new + name = collection.name + inserter = Threaded.insert(name) || Threaded.set_insert(name, Insert.new) count_executions(&block) ensure if @executions.zero? - Threaded.insert = nil + Threaded.set_insert(name, nil) inserter.execute(collection) end end # Execute the block, incrementing the executions before the call and