Methods
Constants
DEFAULT_LOCKING_COLUMN = 'lock_version'
Public Class methods
extended(base)
     # File activerecord/lib/active_record/locking/optimistic.rb, line 139
139:         def self.extended(base)
140:           class <<base
141:             alias_method_chain :update_counters, :lock
142:           end
143:         end
Public Instance methods
locking_column()

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

     # File activerecord/lib/active_record/locking/optimistic.rb, line 160
160:         def locking_column
161:           reset_locking_column
162:         end
locking_enabled?()

Is optimistic locking enabled for this table? 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).

     # File activerecord/lib/active_record/locking/optimistic.rb, line 149
149:         def locking_enabled?
150:           lock_optimistically && columns_hash[locking_column]
151:         end
quoted_locking_column()

Quote the column name used for optimistic locking.

     # File activerecord/lib/active_record/locking/optimistic.rb, line 165
165:         def quoted_locking_column
166:           connection.quote_column_name(locking_column)
167:         end
reset_locking_column()

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

     # File activerecord/lib/active_record/locking/optimistic.rb, line 170
170:         def reset_locking_column
171:           set_locking_column DEFAULT_LOCKING_COLUMN
172:         end
set_locking_column(value = nil, &block)

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

     # File activerecord/lib/active_record/locking/optimistic.rb, line 154
154:         def set_locking_column(value = nil, &block)
155:           define_attr_method :locking_column, value, &block
156:           value
157:         end
update_counters_with_lock(id, counters)

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

     # File activerecord/lib/active_record/locking/optimistic.rb, line 176
176:         def update_counters_with_lock(id, counters)
177:           counters = counters.merge(locking_column => 1) if locking_enabled?
178:           update_counters_without_lock(id, counters)
179:         end