mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #11424 from kennyj/fix_column_defaults_caching
Reset @column_defaults when assigning locking_column.
This commit is contained in:
commit
5a52fbe1cb
3 changed files with 15 additions and 0 deletions
|
@ -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`.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue