Skip to content

Commit

Permalink
Support prebuilt counter cache association list (#554)
Browse files Browse the repository at this point in the history
- ahead of Rails 7.2 releases
  • Loading branch information
JoeDupuis authored Mar 12, 2024
1 parent a0b7632 commit de74493
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,25 @@ def really_destroy!(update_destroy_attributes: true)

private

def counter_cache_disabled?
defined?(@_disable_counter_cache) && @_disable_counter_cache
end

def counter_cached_association_names
return [] if counter_cache_disabled?
super
end

def each_counter_cached_associations
!(defined?(@_disable_counter_cache) && @_disable_counter_cache) ? super : []
return [] if counter_cache_disabled?

if defined?(super)
super
else
counter_cached_association_names.each do |name|
yield association(name)
end
end
end

def paranoia_restore_attributes
Expand Down

0 comments on commit de74493

Please sign in to comment.