我正在为我的模型添加 counter_cache:
用户 (id, org_id) 组织 (id, users_count)
但是出现了以下错误:ArgumentError (未知的键:counter_cache):
class Org < ActiveRecord::Base
has_many :users, :counter_cache => true
class User < ActiveRecord::Base
belongs_to :org
有什么想法是设置错误的吗?我希望Org.users_count返回计数器缓存,以获取该组织中用户数量的#?
rails runner
运行那段代码。 - lucapette