How can I roll my own counter cache for a self-referential many-to-many relationship that uses has_many :through
?
I need to track the number of citations and references for each article
I'm using roughly the code from the answer to this question:
class Publication < ActiveRecord::Base
has_many :citations
has_many :cited_publications, :through => :citations, :source => :reference
has_many :references, :foreign_key => "reference_id", :class_name => "Citation"
has_many :refered_publications, :through => :references, :source => :publication
end
class Citation < ActiveRecord::Base
belongs_to :publication
belongs_to :reference, :class_name => "Publication"
end