module ActiveRecord::Locking::Pessimistic

def lock!(lock = true)

the locked record.
or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns
lock. Pass an SQL locking clause to append the end of the SELECT statement
Obtain a row lock on this record. Reloads the record to obtain the requested
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