Skip to content
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

Merged
merged 1 commit into from Mar 25, 2024

Conversation

casperisfine
Copy link
Contributor

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 #50800

As 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.

@casperisfine
Copy link
Contributor Author

Forgot to cc @seanpdoyle and @davidstosik

@byroot byroot added this to the 7.2.0 milestone Jan 26, 2024
@casperisfine casperisfine force-pushed the infer-inverse-of-deprecation branch 3 times, most recently from 841d9a3 to 0e8c2ce Compare March 21, 2024 14:53
@rails-bot rails-bot bot added the docs label Mar 21, 2024
Copy link
Contributor

@seanpdoyle seanpdoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

Copy link
Member

@Edouard-chin Edouard-chin left a 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 :)

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@byroot byroot merged commit 246b3b6 into rails:main Mar 25, 2024
4 checks passed
tagliala added a commit to ifad/chronomodel that referenced this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants