Skip to content

Commit 8c580d7

Browse files
committed
Reset base_class when the model class is duped or cloned
1 parent 7abd9b5 commit 8c580d7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

activerecord/lib/active_record/inheritance.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ def inherited(subclass)
215215
super
216216
end
217217

218+
def dup # :nodoc:
219+
# `initialize_dup` / `initialize_copy` don't work when defined
220+
# in the `singleton_class`.
221+
other = super
222+
other.set_base_class
223+
other
224+
end
225+
226+
def initialize_clone(other) # :nodoc:
227+
super
228+
set_base_class
229+
end
230+
218231
protected
219232
# Returns the class type of the record using the current module as a prefix. So descendants of
220233
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.

0 commit comments

Comments
 (0)