跳至内容 跳至搜索
方法
L
R
U

常量

DEFAULT_LOCKING_COLUMN = "lock_version"
 

属性

[R] locking_column

用于乐观锁定的版本列。默认值为 lock_version

实例公共方法

locking_column=(value)

设置用于乐观锁定的列。默认值为 lock_version

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

locking_enabled?()

如果 lock_optimistically 标志设置为 true(默认情况下为 true),并且表包含 locking_column 列(默认为 lock_version),则返回 true。

# File activerecord/lib/active_record/locking/optimistic.rb, line 160
def locking_enabled?
  lock_optimistically && columns_hash[locking_column]
end

reset_locking_column()

将用于乐观锁定的列重置回 lock_version 默认值。

# File activerecord/lib/active_record/locking/optimistic.rb, line 174
def reset_locking_column
  self.locking_column = DEFAULT_LOCKING_COLUMN
end

update_counters(id, counters)

确保更新计数器时,锁定版本列也会更新。

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