Closed Cohen-Carlisle closed 2 months ago
For my own understanding, can you show me a situation for which the rule is still needed? When I read about the Rails 7 changes, I got the impression that all of this is handled automatically now
My understanding is that there are still conditions where you need to supply inverse_of
, like if you use a custom foreign key column name or a custom relation name (book.author
joining to the Person
table). I believe it was also mentioned on the Rails PR that implemented automatic_scope_inversing
that if there is a scope/proc on both sides of the relation, it can’t (necessarily?) be automatically inferred.
I can test these out when I’m back home this evening (US Eastern).
Just did some testing and https://guides.rubyonrails.org/association_basics.html#bi-directional-associations is correct that you need to specify inverse_of
on the has_many
side of a relation when using the foreign_key
option on the belongs_to
side. Interestingly, rubocop gets this backwards and tells you to add inverse_of
on the belongs_to
side.
Edit: I found this rubocop-rails issue talking about this problem. Should we lean towards disabling this altogether if it's going to potentially spit out false positives?
This is the second conversation that's made me feel that this cop might be doing the wrong thing. @koic?
@searls how would you like to proceed?
superseded by #54
scope's inverses are automatically inferred with rails 7+
closes #51
I manually tested this locally and it resolved my issue. (Which means I managed not to typo
IgnoreScopes: true
:smile:)