Skip to content

Commit ba877bd

Browse files
committed
Copy config.active_record.* again when ActiveRecord::Base is loaded
Otherwise initializer files with `Rails.application.active_record.*` might break.
1 parent 85622b9 commit ba877bd

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

activerecord/lib/active_record/core.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ def default_timezone # :nodoc:
341341
ActiveRecord.default_timezone
342342
end
343343

344+
def maintain_test_schema # :nodoc:
345+
ActiveRecord.maintain_test_schema
346+
end
347+
344348
def reading_role # :nodoc:
345349
ActiveSupport::Deprecation.warn(<<~MSG)
346350
ActiveRecord::Base.reading_role is deprecated and will be removed in Rails 7.0.

activerecord/lib/active_record/migration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def load_schema_if_pending!
651651
end
652652

653653
def maintain_test_schema! #:nodoc:
654-
if ActiveRecord.maintain_test_schema
654+
if ActiveRecord::Base.maintain_test_schema
655655
suppress_messages { load_schema_if_pending! }
656656
end
657657
end

activerecord/lib/active_record/railtie.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,15 @@ class Railtie < Rails::Railtie # :nodoc:
224224
configs.each do |k, v|
225225
next if k == :encryption
226226
setter = "#{k}="
227-
next if ActiveRecord.respond_to?(setter)
228-
send(setter, v)
227+
# Some existing initializers might rely on Active Record configuration
228+
# being copied from the config object to their actual destination when
229+
# `ActiveRecord::Base` is loaded.
230+
# So to preserve backward compatibility we copy the config a second time.
231+
if ActiveRecord.respond_to?(setter)
232+
ActiveRecord.send(setter, v)
233+
else
234+
send(setter, v)
235+
end
229236
end
230237
end
231238
end

0 commit comments

Comments
 (0)