Skip to content

Commit de74493

Browse files
authored
Support prebuilt counter cache association list (#554)
- ahead of Rails 7.2 releases
1 parent a0b7632 commit de74493

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: lib/paranoia.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,25 @@ def really_destroy!(update_destroy_attributes: true)
173173

174174
private
175175

176+
def counter_cache_disabled?
177+
defined?(@_disable_counter_cache) && @_disable_counter_cache
178+
end
179+
180+
def counter_cached_association_names
181+
return [] if counter_cache_disabled?
182+
super
183+
end
184+
176185
def each_counter_cached_associations
177-
!(defined?(@_disable_counter_cache) && @_disable_counter_cache) ? super : []
186+
return [] if counter_cache_disabled?
187+
188+
if defined?(super)
189+
super
190+
else
191+
counter_cached_association_names.each do |name|
192+
yield association(name)
193+
end
194+
end
178195
end
179196

180197
def paranoia_restore_attributes

0 commit comments

Comments
 (0)