Skip to content

Commit b284f8b

Browse files
authored
Merge pull request rails#51896 from rails/rm-make-invert-opt-in
Don't enable automatically_invert_plural_associations by default
2 parents 15381dd + a8a848d commit b284f8b

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

activerecord/lib/active_record/reflection.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -760,21 +760,9 @@ def automatic_inverse_of
760760

761761
begin
762762
reflection = klass._reflect_on_association(inverse_name)
763-
if !reflection
763+
if !reflection && active_record.automatically_invert_plural_associations
764764
plural_inverse_name = ActiveSupport::Inflector.pluralize(inverse_name)
765765
reflection = klass._reflect_on_association(plural_inverse_name)
766-
767-
if valid_inverse_reflection?(reflection) && !active_record.automatically_invert_plural_associations
768-
ActiveRecord.deprecator.warn(
769-
"The `#{active_record.name}##{name}` inverse association could have been automatically" \
770-
" inferred as `#{klass.name}##{plural_inverse_name}` but wasn't because `automatically_invert_plural_associations`" \
771-
" is disabled.\n\n" \
772-
"If automatic inference is intended, you can consider enabling" \
773-
" `config.active_record.automatically_invert_plural_associations`.\n\n" \
774-
"If automatic inference is not intended, you can silence this warning by defining the association with `inverse_of: nil`."
775-
)
776-
reflection = nil
777-
end
778766
end
779767
rescue NameError => error
780768
raise unless error.name.to_s == class_name

guides/source/configuring.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Below are the default values associated with each target version. In cases of co
6161
#### Default Values for Target Version 7.2
6262

6363
- [`config.active_job.enqueue_after_transaction_commit`](#config-active-job-enqueue-after-transaction-commit): `:default`
64-
- [`config.active_record.automatically_invert_plural_associations`](#config-active-record-automatically-invert-plural-associations): `true`
6564
- [`config.active_record.postgresql_adapter_decode_dates`](#config-active-record-postgresql-adapter-decode-dates): `true`
6665
- [`config.active_record.validate_migration_timestamps`](#config-active-record-validate-migration-timestamps): `true`
6766
- [`config.active_storage.web_image_content_types`](#config-active-storage-web-image-content-types): `%w[image/png image/jpeg image/gif image/webp]`
@@ -1106,6 +1105,10 @@ class Comment < ApplicationRecord
11061105
end
11071106
```
11081107
1108+
| Starting with version | The default value is |
1109+
| --------------------- | -------------------- |
1110+
| (original) | `false` |
1111+
11091112
#### `config.active_record.validate_migration_timestamps`
11101113
11111114
Controls whether to validate migration timestamps. When set, an error will be raised if the

railties/lib/rails/application/configuration.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ def load_defaults(target_version)
332332
if respond_to?(:active_record)
333333
active_record.postgresql_adapter_decode_dates = true
334334
active_record.validate_migration_timestamps = true
335-
active_record.automatically_invert_plural_associations = true
336335
end
337336
when "8.0"
338337
load_defaults "7.2"

0 commit comments

Comments
 (0)