Say I have A which has many B which has many C, ideally I want the quickest way to get the count of C for A, a counter cache through an association with B would do - but I don't think that exists. Any ideas?
No the counter_cache is on the belongs_to and if I try adding through on the belongs to then it whinges, e.g. on C:
belongs_to :a, through => :b, :counter_cache => true
I get the error undefined local variable or method 'through'
-D
What I've ended up doing is the following
class C < ActiveRecord::Base belongs_to :B
after_create :increment_A_counter_cache after_destroy :decrement_A_counter_cache
private
def increment_A_counter_cache A.increment_counter( 'c_count', self.B.A.id ) end
def decrement_A_counter_cache A.decrement_counter( 'c_count', self.B.A.id ) end end
It seems to work, I was just wondering if there was a way to do it through the framework.
-D