forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cases and a fix for rails#10865.
Assuming Topic has_many Replies and Reply belongs_to Topic, the counter cache was incremented twice if reply is saved after reassignment, as follows: reply.topic = topic # triggers BelongsToAssocation#replace reply.save # triggers belongs_to_counter_cache_after_update The problem is caused by duplicate work. This commit adds a flag to the reply if it has already triggered an increment, but has not been saved yet. Thus, when the reply is actually saved, the superfluous increment does not occur. Note the following edge case: reply.topic = t1 # not saved, but counter updated t2.replies << t2 # save! called, previous change needs to be undone
- Loading branch information
Jiunn Haur Lim
committed
Jul 25, 2013
1 parent
7af0ae9
commit 52e30db
Showing
3 changed files
with
71 additions
and
15 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