instance method
with_lock
Ruby on Rails 8.1.2
Since v3.2.22.5Signature
with_lock(*args)
Wraps the passed block in a transaction, reloading the object with a lock before yielding. 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 97
def with_lock(*args)
transaction_opts = args.extract_options!
lock = args.present? ? args.first : true
transaction(**transaction_opts) do
lock!(lock)
yield
end
end
Defined in activerecord/lib/active_record/locking/pessimistic.rb line 97
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Locking::Pessimistic