Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reset @column_defaults when assigning .

  • Loading branch information...
commit 33354aa23e9d34bdf5aae8ab942cf830bf9f2782 1 parent 4f8168e
@kennyj kennyj authored
View
13 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`.
View
1  activerecord/lib/active_record/locking/optimistic.rb
@@ -138,6 +138,7 @@ def locking_enabled?
# 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
View
1  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
Please sign in to comment.
Something went wrong with that request. Please try again.