23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/dm-counter-cache.rb', line 23
def setup_with_counter_caching(name, model, options = {})
perform_counter_cache = options.delete(:counter_cache)
relationship = setup_without_counter_caching(name, model, options)
if perform_counter_cache
counter_cache_attribute = case perform_counter_cache
when String, Symbol
perform_counter_cache.to_sym
else
"#{model.storage_name}_count".to_sym
end
model.extend(ModelClassMethods)
model.__send__(:include, InstanceMethods)
model.define_counter_cache_callbacks_for(relationship, counter_cache_attribute)
end
relationship
end
|