Skip to content

Commit 6758b86

Browse files
committed
Emit deprecation warning about inverse_of inference only for valid reflections
That is, if the reflection found is not valid, we don't want to emit the warning because it's misleading. It says the inverse association could have been automatically inferred but wasn't because `automatically_invert_plural_associations` is disabled. However, this is not true, because later on, when we check whether the reflection is valid, we see it's not, and end up returning `nil`.
1 parent 8e46af8 commit 6758b86

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

activerecord/lib/active_record/reflection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def automatic_inverse_of
708708
plural_inverse_name = ActiveSupport::Inflector.pluralize(inverse_name)
709709
reflection = klass._reflect_on_association(plural_inverse_name)
710710

711-
if reflection && !active_record.automatically_invert_plural_associations
711+
if valid_inverse_reflection?(reflection) && !active_record.automatically_invert_plural_associations
712712
ActiveRecord.deprecator.warn(
713713
"The `#{active_record.name}##{name}` inverse association could have been automatically" \
714714
" inferred as `#{klass.name}##{plural_inverse_name}` but wasn't because `automatically_invert_plural_associations`" \

0 commit comments

Comments
 (0)