diff options
author | Mingdong Luo <mdluo@nsmss.com> | 2015-01-31 19:23:48 -0800 |
---|---|---|
committer | Mingdong Luo <mdluo@nsmss.com> | 2015-01-31 19:23:48 -0800 |
commit | 549d171a90135999e3c670f489494b7a39dd6dd7 (patch) | |
tree | 233466527b797fe3ea7c6a7a3673795cea28aebe /activerecord/lib/active_record/locking | |
parent | c840b18ac31a852d99ff760229f2c087b6961727 (diff) | |
parent | 70ac072976c8cc6f013f0df3777e54ccae3f4f8c (diff) | |
download | rails-549d171a90135999e3c670f489494b7a39dd6dd7.tar.gz rails-549d171a90135999e3c670f489494b7a39dd6dd7.tar.bz2 rails-549d171a90135999e3c670f489494b7a39dd6dd7.zip |
Merge branch 'master' into pr/18316
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/locking')
-rw-r--r-- | activerecord/lib/active_record/locking/optimistic.rb | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 9f053453bd..008cda46cd 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -66,6 +66,15 @@ module ActiveRecord send(lock_col + '=', previous_lock_value + 1) end + def _create_record(attribute_names = self.attribute_names, *) # :nodoc: + if locking_enabled? + # We always want to persist the locking version, even if we don't detect + # a change from the default, since the database might have no default + attribute_names |= [self.class.locking_column] + end + super + end + def _update_record(attribute_names = self.attribute_names) #:nodoc: return super unless locking_enabled? return 0 if attribute_names.empty? @@ -116,12 +125,8 @@ module ActiveRecord relation = super if locking_enabled? - column_name = self.class.locking_column - column = self.class.columns_hash[column_name] - substitute = self.class.connection.substitute_at(column) - - relation = relation.where(self.class.arel_table[column_name].eq(substitute)) - relation.bind_values << [column, self[column_name].to_i] + locking_column = self.class.locking_column + relation = relation.where(locking_column => _read_attribute(locking_column)) end relation @@ -139,7 +144,7 @@ module ActiveRecord # Set the column to use for optimistic locking. Defaults to +lock_version+. def locking_column=(value) - clear_caches_calculated_from_columns + reload_schema_from_cache @locking_column = value.to_s end @@ -185,11 +190,6 @@ module ActiveRecord super.to_i end - def changed?(old_value, *) - # Ensure we save if the default was `nil` - super || old_value == 0 - end - def init_with(coder) __setobj__(coder['subtype']) end |