1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Reset base_class when the model class is duped or cloned

This commit is contained in:
Jean Boussier 2021-04-11 10:50:59 +02:00
parent 7abd9b5f66
commit 8c580d716f

View file

@ -215,6 +215,19 @@ module ActiveRecord
super
end
def dup # :nodoc:
# `initialize_dup` / `initialize_copy` don't work when defined
# in the `singleton_class`.
other = super
other.set_base_class
other
end
def initialize_clone(other) # :nodoc:
super
set_base_class
end
protected
# Returns the class type of the record using the current module as a prefix. So descendants of
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.