aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2013-07-13 22:02:05 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2013-07-13 22:02:05 -0700
commit5a52fbe1cbfe3c58184f33ca1bfc451e6e473284 (patch)
treea935947cda24a604a3c7eeea203a22e3ad638915
parentba8b55f7911b4a74e151639150f997cca47488c9 (diff)
parent33354aa23e9d34bdf5aae8ab942cf830bf9f2782 (diff)
downloadrails-5a52fbe1cbfe3c58184f33ca1bfc451e6e473284.tar.gz
rails-5a52fbe1cbfe3c58184f33ca1bfc451e6e473284.tar.bz2
rails-5a52fbe1cbfe3c58184f33ca1bfc451e6e473284.zip
Merge pull request #11424 from kennyj/fix_column_defaults_caching
Reset @column_defaults when assigning locking_column.
-rw-r--r--activerecord/CHANGELOG.md13
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb1
-rw-r--r--activerecord/test/cases/locking_test.rb1
3 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 1eb2f2d130..404443f4ad 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,16 @@
+* Reset @column_defaults when assigning `locking_column`.
+ We had a potential problem. For example:
+
+ class Post < ActiveRecord::Base
+ self.column_defaults # if we call this unintentionally before setting locking_column ...
+ self.locking_column = 'my_locking_column'
+ end
+
+ Post.column_defaults["my_locking_column"]
+ => nil # expected value is 0 !
+
+ *kennyj*
+
* Remove extra select and update queries on save/touch/destroy ActiveRecord model
with belongs to reflection with option `touch: true`.
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index 209de78898..2a7996c4e7 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -138,6 +138,7 @@ module ActiveRecord
# Set the column to use for optimistic locking. Defaults to +lock_version+.
def locking_column=(value)
+ @column_defaults = nil
@locking_column = value.to_s
end
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index 827fcf3d50..db7d3b80ab 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -17,6 +17,7 @@ class LockWithoutDefault < ActiveRecord::Base; end
class LockWithCustomColumnWithoutDefault < ActiveRecord::Base
self.table_name = :lock_without_defaults_cust
+ self.column_defaults # to test @column_defaults caching.
self.locking_column = :custom_lock_version
end