aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-23 01:49:40 +0900
committerGitHub <noreply@github.com>2018-01-23 01:49:40 +0900
commitc177bca26cbc08f8dfb1e3a68613a89e6a035783 (patch)
treebd19f9c4b9452e4961bbcbe16002cb370d9c76ca /activerecord/lib
parent7bb0b397ea51b0e41b5ebdf4fe5edcfc7345b600 (diff)
parent3562331669443b600f1cf9fd93a0cddaaf94d319 (diff)
downloadrails-c177bca26cbc08f8dfb1e3a68613a89e6a035783.tar.gz
rails-c177bca26cbc08f8dfb1e3a68613a89e6a035783.tar.bz2
rails-c177bca26cbc08f8dfb1e3a68613a89e6a035783.zip
Merge pull request #30535 from leonelgalan/becomes_and_default_inheritance
Ignores a default subclass when `becomes(Parent)`
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/persistence.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index cdd54cc502..a45d011d75 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -359,7 +359,8 @@ module ActiveRecord
# Any change to the attributes on either instance will affect both instances.
# If you want to change the sti column as well, use #becomes! instead.
def becomes(klass)
- became = klass.new
+ became = klass.allocate
+ became.send(:initialize)
became.instance_variable_set("@attributes", @attributes)
became.instance_variable_set("@mutations_from_database", @mutations_from_database) if defined?(@mutations_from_database)
became.instance_variable_set("@new_record", new_record?)