instance method
with_lock
Ruby on Rails edge
Since v3.2.22.5Signature
with_lock(*args)
Wraps the passed block in a transaction, reloading the object with a lock before yielding. Yields the current transaction so you can register callbacks. You can pass the SQL locking clause as an optional argument (see #lock!).
You can also pass options like requires_new:, isolation:, and joinable: to the wrapping transaction (see ActiveRecord::ConnectionAdapters::DatabaseStatements#transaction).
Parameters
-
argsrest
Source
# File activerecord/lib/active_record/locking/pessimistic.rb, line 100
def with_lock(*args)
transaction_opts = args.extract_options!
lock = args.present? ? args.first : true
transaction(**transaction_opts) do |transaction|
lock!(lock)
yield transaction
end
end
Defined in activerecord/lib/active_record/locking/pessimistic.rb line 100
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Locking::Pessimistic