Method: Mongoid#unit_of_work

Defined in:
lib/mongoid.rb

#unit_of_workObject

We can process a unit of work in Mongoid and have the identity map automatically clear itself out after the work is complete.

Examples:

Process a unit of work.

Mongoid.unit_of_work do
  Person.create(:title => "Sir")
end

Since:

  • 2.1.0



130
131
132
133
134
135
136
# File 'lib/mongoid.rb', line 130

def unit_of_work
  begin
    yield if block_given?
  ensure
    IdentityMap.clear
  end
end