instance method
lock!
Ruby on Rails 6.0.6
Since v2.2.3Signature
lock!(lock = true)
Obtain a row lock on this record. Reloads the record to obtain the requested lock. Pass an SQL locking clause to append the end of the SELECT statement or pass true for “FOR UPDATE” (the default, an exclusive row lock). Returns the locked record.
Parameters
-
lockopt = true
Source
# File activerecord/lib/active_record/locking/pessimistic.rb, line 63
def lock!(lock = true)
if persisted?
if has_changes_to_save?
raise(<<-MSG.squish)
Locking a record with unpersisted changes is not supported. Use
`save` to persist the changes, or `reload` to discard them
explicitly.
MSG
end
reload(lock: lock)
end
self
end
Defined in activerecord/lib/active_record/locking/pessimistic.rb line 63
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Locking::Pessimistic