module ActiveRecord::Locking::Optimistic::ClassMethods

Constants

DEFAULT_LOCKING_COLUMN

Public Instance Methods

locking_column() Show source
# File activerecord/lib/active_record/locking/optimistic.rb, line 141
def locking_column
  @locking_column = DEFAULT_LOCKING_COLUMN unless defined?(@locking_column)
  @locking_column
end

The version column used for optimistic locking. Defaults to lock_version.

locking_column=(value) Show source
# File activerecord/lib/active_record/locking/optimistic.rb, line 135
def locking_column=(value)
  reload_schema_from_cache
  @locking_column = value.to_s
end

Set the column to use for optimistic locking. Defaults to lock_version.

locking_enabled?() Show source
# File activerecord/lib/active_record/locking/optimistic.rb, line 130
def locking_enabled?
  lock_optimistically && columns_hash[locking_column]
end

Returns true if the lock_optimistically flag is set to true (which it is, by default) and the table includes the locking_column column (defaults to lock_version).

reset_locking_column() Show source
# File activerecord/lib/active_record/locking/optimistic.rb, line 147
def reset_locking_column
  self.locking_column = DEFAULT_LOCKING_COLUMN
end

Reset the column used for optimistic locking back to the lock_version default.

update_counters(id, counters) Show source
# File activerecord/lib/active_record/locking/optimistic.rb, line 153
def update_counters(id, counters)
  counters = counters.merge(locking_column => 1) if locking_enabled?
  super
end

Make sure the lock version column gets updated when counters are updated.

Calls superclass method

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.