aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/locking/optimistic.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-22 19:11:11 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-22 19:24:16 +0000
commit7edade337e968fb028b2b6abfa579120eb424039 (patch)
treef44f5381296ac54920a8a29f528cbcbec4bedd2f /activerecord/lib/active_record/locking/optimistic.rb
parent89e2647da6fade8397963fc0c0159eee4f3fd842 (diff)
downloadrails-7edade337e968fb028b2b6abfa579120eb424039.tar.gz
rails-7edade337e968fb028b2b6abfa579120eb424039.tar.bz2
rails-7edade337e968fb028b2b6abfa579120eb424039.zip
Make read_attribute code path accessible at the class level
Diffstat (limited to 'activerecord/lib/active_record/locking/optimistic.rb')
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb27
1 files changed, 12 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index ce0a165660..0e33cdb617 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -64,21 +64,6 @@ module ActiveRecord
send(lock_col + '=', previous_lock_value + 1)
end
- def attributes_from_column_definition
- result = self.class.column_defaults.dup
-
- # 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.
-
- if result.key?(self.class.locking_column) && lock_optimistically
- result[self.class.locking_column] ||= 0
- end
-
- result
- end
-
def update(attribute_names = @attributes.keys) #:nodoc:
return super unless locking_enabled?
return 0 if attribute_names.empty?
@@ -180,6 +165,18 @@ module ActiveRecord
counters = counters.merge(locking_column => 1) if locking_enabled?
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) #:nodoc:
+ if attributes.key?(locking_column) && lock_optimistically
+ attributes[locking_column] ||= 0
+ end
+
+ attributes
+ end
end
end
end