diff options
author | Miklos Fazekas <mfazekas@szemafor.com> | 2014-10-02 10:02:30 +0200 |
---|---|---|
committer | Miklos Fazekas <mfazekas@szemafor.com> | 2015-02-04 15:42:14 +0100 |
commit | 5f6370a81bd013b801f3e4842ffd466d756d127d (patch) | |
tree | f4901908bbb0331a816027251e6394a0c53653b2 /activerecord/lib/active_record/persistence.rb | |
parent | 1405c7a2cb3539880ebd82c287040b55d289a427 (diff) | |
download | rails-5f6370a81bd013b801f3e4842ffd466d756d127d.tar.gz rails-5f6370a81bd013b801f3e4842ffd466d756d127d.tar.bz2 rails-5f6370a81bd013b801f3e4842ffd466d756d127d.zip |
Always reset changed attributes in becomes
When ```becomes``` changes @attributes it should also change
@changed_attributes. Otherwise we'll experience a kind of split head situation
where attributes are coming from ```self```, but changed_attributes is coming
from ```klass.new```. This affects the inheritance_colmn as it's changed by new
for example.
Fixes #16881
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index af7aef6e43..f89f2fbcfa 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -208,7 +208,8 @@ module ActiveRecord def becomes(klass) became = klass.new became.instance_variable_set("@attributes", @attributes) - became.instance_variable_set("@changed_attributes", @changed_attributes) if defined?(@changed_attributes) + changed_attributes = @changed_attributes if defined?(@changed_attributes) + became.instance_variable_set("@changed_attributes", changed_attributes || {}) became.instance_variable_set("@new_record", new_record?) became.instance_variable_set("@destroyed", destroyed?) became.instance_variable_set("@errors", errors) |