forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't rely on the counter_cache to destroy childrens:
- rails#35127 introduced a new change to not make a query when the counter cache value of the parent is 0. The implementation was overwriting the `find_target?` method from `AR::Associaton`. This had the side effect of making `Topic.comments.destroy_all` to not destroy anything in some circumstances. The bug was mainly happening during test because the counter_cache value isn't set when fixtures load. This resulted in the `find_target` method to return the in memory target (empty array) instead of getting it from the DB. This PR removes the `find_target?` overwritten method in HasManyAssociation and inline the condition inside methods that needs it (such as `size` and `load_target` which is used by `to_ary`). Even though the root cause of the problem was mainly happening in test, I decided to opt-out the `destroy_all` from checking the counter cache value has this could cause potential issue if fonr any reason the counter cacher get desync.
- Loading branch information
1 parent
1bbf08b
commit 2884503
Showing
3 changed files
with
18 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters