module ActiveRecord::CounterCache
Active Record Counter Cache¶ ↑
Private Instance Methods
_create_record(attribute_names = self.attribute_names)
click to toggle source
Calls superclass method
# File lib/active_record/counter_cache.rb, line 165 def _create_record(attribute_names = self.attribute_names) id = super each_counter_cached_associations do |association| association.increment_counters end id end
destroy_row()
click to toggle source
Calls superclass method
# File lib/active_record/counter_cache.rb, line 175 def destroy_row affected_rows = super if affected_rows > 0 each_counter_cached_associations do |association| foreign_key = association.reflection.foreign_key.to_sym unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key association.decrement_counters end end end affected_rows end
each_counter_cached_associations() { |association(to_sym)| ... }
click to toggle source
# File lib/active_record/counter_cache.rb, line 190 def each_counter_cached_associations _reflections.each do |name, reflection| yield association(name.to_sym) if reflection.belongs_to? && reflection.counter_cache_column end end