Method: ActiveRecord::Acts::Versioned::Behaviors::ClassMethods#without_locking

Defined in:
lib/acts_as_versioned/lib/acts_as_versioned.rb

#without_locking(&block) ⇒ Object

Turns off optimistic locking for the duration of the block

Foo.without_locking do
  @foo.save
end


481
482
483
484
485
486
487
488
489
# File 'lib/acts_as_versioned/lib/acts_as_versioned.rb', line 481

def without_locking(&block)
  current = ActiveRecord::Base.lock_optimistically
  ActiveRecord::Base.lock_optimistically = false if current
  begin
    block.call
  ensure
    ActiveRecord::Base.lock_optimistically = true if current
  end
end