diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2014-04-13 12:24:59 -0400 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2014-04-13 12:24:59 -0400 |
commit | 655a3667aa99ae3f7e68024b3971b5783d6396bf (patch) | |
tree | 503784ae3b12d6b48243a45165fb2c1ff65ca72a /activerecord/lib/active_record/counter_cache.rb | |
parent | dd063f6ef436b5e6a594e70eeb50532a09ef7a57 (diff) | |
download | rails-655a3667aa99ae3f7e68024b3971b5783d6396bf.tar.gz rails-655a3667aa99ae3f7e68024b3971b5783d6396bf.tar.bz2 rails-655a3667aa99ae3f7e68024b3971b5783d6396bf.zip |
Make counter cache decrementation on destroy idempotent
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index dcbdf75627..a5897edf03 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -118,5 +118,26 @@ module ActiveRecord update_counters(id, counter_name => -1) end end + + protected + + def actually_destroyed? + @_actually_destroyed + end + + def clear_destroy_state + @_actually_destroyed = nil + end + + private + + def destroy_row + affected_rows = super + + @_actually_destroyed = affected_rows > 0 + + affected_rows + end + end end |