From 655a3667aa99ae3f7e68024b3971b5783d6396bf Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sun, 13 Apr 2014 12:24:59 -0400 Subject: Make counter cache decrementation on destroy idempotent --- activerecord/lib/active_record/counter_cache.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/lib/active_record/counter_cache.rb') 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 -- cgit v1.2.3