lib/counter_culture/extensions.rb in counter_culture-1.11.0 vs lib/counter_culture/extensions.rb in counter_culture-1.12.0

- old
+ new

@@ -17,20 +17,31 @@ unless @after_commit_counter_cache include AfterCommitAction unless include?(AfterCommitAction) # initialize callbacks only once after_create :_update_counts_after_create + before_destroy :_update_counts_after_destroy, if: -> (model) do if model.respond_to?(:paranoia_destroyed?) !model.paranoia_destroyed? else true end end + after_update :_update_counts_after_update + if respond_to?(:before_restore) before_restore :_update_counts_after_create, if: -> (model) { model.deleted? } + end + + if defined?(Discard::Model) && include?(Discard::Model) + before_discard :_update_counts_after_destroy, + if: ->(model) { !model.discarded? } + + before_undiscard :_update_counts_after_create, + if: ->(model) { model.discarded? } end # we keep a list of all counter caches we must maintain @after_commit_counter_cache = [] end