Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support prebuilt counter cache association list #554

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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