Methods
Constants
DEFAULT_LOCKING_COLUMN | = | "lock_version" |
Instance Public methods
locking_column()
The version column used for optimistic locking. Defaults to lock_version
.
📝 Source code
# File activerecord/lib/active_record/locking/optimistic.rb, line 142
def locking_column
@locking_column = DEFAULT_LOCKING_COLUMN unless defined?(@locking_column)
@locking_column
end
🔎 See on GitHub
locking_column=(value)
Set the column to use for optimistic locking. Defaults to lock_version
.
📝 Source code
# File activerecord/lib/active_record/locking/optimistic.rb, line 136
def locking_column=(value)
reload_schema_from_cache
@locking_column = value.to_s
end
🔎 See on GitHub
locking_enabled?()
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
).
📝 Source code
# File activerecord/lib/active_record/locking/optimistic.rb, line 131
def locking_enabled?
lock_optimistically && columns_hash[locking_column]
end
🔎 See on GitHub
reset_locking_column()
Reset the column used for optimistic locking back to the lock_version
default.
📝 Source code
# File activerecord/lib/active_record/locking/optimistic.rb, line 148
def reset_locking_column
self.locking_column = DEFAULT_LOCKING_COLUMN
end
🔎 See on GitHub
update_counters(id, counters)
Make sure the lock version column gets updated when counters are updated.
📝 Source code
# File activerecord/lib/active_record/locking/optimistic.rb, line 154
def update_counters(id, counters)
counters = counters.merge(locking_column => 1) if locking_enabled?
super
end
🔎 See on GitHub