Skip to content

Commit c3f4307

Browse files
committed
Define deprecated delegators for the cattr that were moved out of AR::Base
Most of them are considered public API, so we first need to deprecate before we can entirely remove them.
1 parent e581678 commit c3f4307

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,15 @@ def add_pg_encoders
909909
end
910910

911911
def update_typemap_for_default_timezone
912-
if @default_timezone != ActiveRecord::Base.default_timezone && @timestamp_decoder
913-
decoder_class = ActiveRecord::Base.default_timezone == :utc ?
912+
if @default_timezone != ActiveRecord.default_timezone && @timestamp_decoder
913+
decoder_class = ActiveRecord.default_timezone == :utc ?
914914
PG::TextDecoder::TimestampUtc :
915915
PG::TextDecoder::TimestampWithoutTimeZone
916916

917917
@timestamp_decoder = decoder_class.new(@timestamp_decoder.to_h)
918918
@connection.type_map_for_results.add_coder(@timestamp_decoder)
919919

920-
@default_timezone = ActiveRecord::Base.default_timezone
920+
@default_timezone = ActiveRecord.default_timezone
921921

922922
# if default timezone has changed, we need to reconfigure the connection
923923
# (specifically, the session time zone)

activerecord/lib/active_record/core.rb

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,28 +337,33 @@ def find_by!(*args) # :nodoc:
337337
find_by(*args) || raise(RecordNotFound.new("Couldn't find #{name}", name))
338338
end
339339

340-
def default_timezone # :nodoc:
341-
ActiveRecord.default_timezone
342-
end
343-
344340
def maintain_test_schema # :nodoc:
345341
ActiveRecord.maintain_test_schema
346342
end
347343

348-
def reading_role # :nodoc:
349-
ActiveSupport::Deprecation.warn(<<~MSG)
350-
ActiveRecord::Base.reading_role is deprecated and will be removed in Rails 7.1.
351-
Use `ActiveRecord.reading_role` instead.
352-
MSG
353-
ActiveRecord.reading_role
354-
end
344+
%w(
345+
reading_role writing_role legacy_connection_handling default_timezone index_nested_attribute_errors
346+
verbose_query_logs queues maintain_test_schema warn_on_records_fetched_greater_than
347+
application_record_class action_on_strict_loading_violation schema_format error_on_ignored_order
348+
timestamped_migrations dump_schema_after_migration dump_schemas suppress_multiple_database_warning
349+
).each do |attr|
350+
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
351+
def #{attr}
352+
ActiveSupport::Deprecation.warn(<<~MSG)
353+
ActiveRecord::Base.#{attr} is deprecated and will be removed in Rails 7.1.
354+
Use `ActiveRecord.#{attr}` instead.
355+
MSG
356+
ActiveRecord.#{attr}
357+
end
355358
356-
def writing_role # :nodoc:
357-
ActiveSupport::Deprecation.warn(<<~MSG)
358-
ActiveRecord::Base.writing_role is deprecated and will be removed in Rails 7.1.
359-
Use `ActiveRecord.writing_role` instead.
360-
MSG
361-
ActiveRecord.writing_role
359+
def #{attr}=(value)
360+
ActiveSupport::Deprecation.warn(<<~MSG)
361+
ActiveRecord::Base.#{attr}= is deprecated and will be removed in Rails 7.1.
362+
Use `ActiveRecord.#{attr}=` instead.
363+
MSG
364+
ActiveRecord.#{attr} = value
365+
end
366+
RUBY
362367
end
363368

364369
def initialize_generated_modules # :nodoc:

0 commit comments

Comments
 (0)