I have read this isnt possible, and then someone else told me it is. They gave me this code but then had to go, now now my app is broken until I get this working :/
I have a Tag model, and each tag has_many resources :through => resource tags. Each resource also has_many tags.
I need to know the number of resource each tag has (I dont care about the other way around).
The problem is it says unkown key cache_counter
This is my model
Tag.rb
has_many :resource_tags, :dependent => :destroy, :counter_cache => :resource_count
has_many :resources, :through => :resource_tags
Resource.rb
has_many :resource_tags, :dependent => :destroy
has_many :tags, :through => :resource_tags
My migration:
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name
t.integer :resource_count, :default => 0
t.timestamps
end
end
end
:counter_cacheoption is forbelongs_tomethodin resorce_tag model
and i think it is better to name column
resources_count(plural)