18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ar_async_counter_cache/active_record.rb', line 18
def belongs_to(association_id, options={})
column = async_counter_cache_column(options.delete(:async_counter_cache))
raise "Please don't use both async_counter_cache and counter_cache." if column && options[:counter_cache]
super(association_id, options)
if column
self.async_counter_types[association_id] = column
reflection = self.reflect_on_association(association_id)
parent_class = reflection.klass
parent_class.send(:attr_readonly, column.to_sym) if defined?(parent_class) && parent_class.respond_to?(:attr_readonly)
parent_id_column = reflection.primary_key_name
add_callbacks(parent_class.to_s, parent_id_column, column)
end
end
|