-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Fix counter_cache create/concat with overlapping counter_cache_column #41321
Fix counter_cache create/concat with overlapping counter_cache_column #41321
Conversation
27acec4
to
6283ea3
Compare
f87328b
to
a944e97
Compare
a944e97
to
961ebf9
Compare
Would be great if somebody from the could take a look at this one :) |
bump 🏓 |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Fix when multiple `belongs_to` maps to the same counter_cache column. In such situation `inverse_which_updates_counter_cache` may find the wrong relation which leads into an invalid increment of the counter_cache. This is done by improving the inverse relation detection in 2 ways: - by comparing `inverse.klass` with the current `active_record` (doesn't work for polymorphic) - by relying on `inverse_of` The above adjustments allows to correctly map the `inverse_which_updates_counter_cache` for both non-polymorphic/polymorphic relations. Fixes rails#41250
961ebf9
to
b25f3e5
Compare
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
still relevant |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@@ -298,6 +300,11 @@ def actual_source_reflection # FIXME: this is a horrible name | |||
self | |||
end | |||
|
|||
def klass_suppress_errors |
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.
This doesn't feel great... can you elaborate on why it's required?
(Do we have a more general "candidate associations that might be my inverse" lookup elsewhere that we can lean on here?)
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
will check as soon as I can, sorry |
Summary
Fix when multiple
belongs_to
maps to the same counter_cache column.In such situation
inverse_which_updates_counter_cache
may find the wrong relation which leads into an invalid increment of the counter_cache.This is done by improving the inverse relation detection in 2 ways:
inverse.klass
with the currentactive_record
(doesn't work for polymorphic)inverse_of
The above adjustments allows to correctly map the
inverse_which_updates_counter_cache
for both non-polymorphic/polymorphic relations.Fixes #41250