Skip to content

Commit a8a848d

Browse files
committed
Don't enable automatically_invert_plural_associations by default
This can cause a lot of issues that are hard to detect. It is better to make this opt-in for people that want to use it. In Rails 8 we can revisit if we want to enable this config by default.
1 parent 62501c7 commit a8a848d

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]`
@@ -1095,6 +1094,10 @@ class Comment < ApplicationRecord
10951094
end
10961095
```
10971096
1097+
| Starting with version | The default value is |
1098+
| --------------------- | -------------------- |
1099+
| (original) | `false` |
1100+
10981101
#### `config.active_record.validate_migration_timestamps`
10991102
11001103
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
@@ -329,7 +329,6 @@ def load_defaults(target_version)
329329
if respond_to?(:active_record)
330330
active_record.postgresql_adapter_decode_dates = true
331331
active_record.validate_migration_timestamps = true
332-
active_record.automatically_invert_plural_associations = true
333332
end
334333
when "8.0"
335334
load_defaults "7.2"

0 commit comments

Comments
 (0)