Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:33:18+00:00 2026-06-07T04:33:18+00:00

I have read this isnt possible, and then someone else told me it is.

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:33:23+00:00Added an answer on June 7, 2026 at 4:33 am

    :counter_cache option is for belongs_to method

    in resorce_tag model

    belongs_to :tag, :counter_cache => :resource_count
    

    and i think it is better to name column resources_count (plural)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read this question and the simple and clear answer but it's not
I have read this question but it's not quite what I was looking for.
I have read from this article http://codahale.com/how-to-safely-store-a-password/ and it says using a salt isn't
I have read this thread when I got the the git: command not found
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is
I have read this. Jquery checkbox <input type=checkbox name=checkGroup id=all> <input type=checkbox name=checkGroup id=one
I have read this in order to compile NH spatial for Nhibernate 3.1 http://build-failed.blogspot.it/2012/02/nhibernate-spatial-part-2.html
First let me say I have read this useful article thoroughly and am using
I have read over this which sort of gives an explanation of when you'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.