Method: ActiveRecord::Locking::Pessimistic#lock!
- Defined in:
- activerecord/lib/active_record/locking/pessimistic.rb
#lock!(lock = true) ⇒ Object
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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'activerecord/lib/active_record/locking/pessimistic.rb', line 69 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. Changed attributes: #{changed.map(&:inspect).join(', ')}. MSG end reload(lock: lock) end self end |