New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put plural inverse association inference behind a configuration flag #50883
Conversation
Forgot to cc @seanpdoyle and @davidstosik |
...ib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt
Outdated
Show resolved
Hide resolved
...ib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt
Outdated
Show resolved
Hide resolved
841d9a3
to
0e8c2ce
Compare
0e8c2ce
to
1416392
Compare
1416392
to
b8166e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor suggestions :)
...ib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt
Outdated
Show resolved
Hide resolved
@@ -11,6 +11,7 @@ module Reflection # :nodoc: | |||
class_attribute :_reflections, instance_writer: false, default: {} | |||
class_attribute :aggregate_reflections, instance_writer: false, default: {} | |||
class_attribute :automatic_scope_inversing, instance_writer: false, default: false | |||
class_attribute :automatically_invert_plural_associations, instance_writer: false, default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casperisfine #50280 also involves automatic inversion (for delegated type associations).
If it were to be merged, would it make sense to put it behind a configuration flag of its own? Would it be appropriate to make this PR's configuration flag general enough to also apply for both scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally anything that could cause backward compatibility issues should be behind a flag to allow to deprecation and selective upgrade, so yes.
As for sharing the same flag, I think it would be weird because the names wouldn't match.
Ref: rails#50284 While having the inverse association configured it generally positive as it avoid some extra queries etc, infering it may break legecy code, as evidenced by how it broke `ActiveStorage::Blob` in rails#50800 As such we can't just enable this behavior immediately, we need to provide and upgrade path for users.
b8166e3
to
7a8e58b
Compare
Ref: - rails/rails@7a8e58b - rails/rails#50883 Close #278
Ref: #50284
While having the inverse association configured it generally positive as it avoid some extra queries etc, infering it may break legecy code, as evidenced by how it broke
ActiveStorage::Blob
in #50800As such we can't just enable this behavior immediately, we need to provide and upgrade path for users.
At this stage this PR is just a quick draft to discuss how exactly we should gate this. We can just make it a regular framework default, but perhaps emitting a deprecation warning when we would have infered the inverse relation would help users upgrade? cc @rafaelfranca as you generally have great insights on this kind of new framework default.