提交 8fcd9b6e 编写于 作者: J Jon Leighton

The default value can be set once in #column_defaults

Rather than doing it every time an instance is instantiated.
上级 f396c01d
......@@ -168,16 +168,16 @@ def update_counters(id, counters)
super
end
# If the locking column has no default value set,
# start the lock version at zero. Note we can't use
# <tt>locking_enabled?</tt> at this point as
# <tt>@attributes</tt> may not have been initialized yet.
def initialize_attributes(attributes, options = {}) #:nodoc:
if attributes.key?(locking_column) && lock_optimistically
attributes[locking_column] ||= 0
end
def column_defaults
@column_defaults ||= begin
defaults = super
if defaults.key?(locking_column) && lock_optimistically
defaults[locking_column] ||= 0
end
attributes
defaults
end
end
end
end
......
......@@ -312,6 +312,13 @@ def reset_column_information
@relation = nil
end
# This is a hook for use by modules that need to do extra stuff to
# attributes when they are initialized. (e.g. attribute
# serialization)
def initialize_attributes(attributes, options = {}) #:nodoc:
attributes
end
private
# Guesses the table name, but does not decorate it with prefix and suffix information.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册