No release in over 3 years
Low commit activity in last 3 years
counter cache that lives in its own table
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

detached_counter_cache

Build Status

detached_counter_cache is a tool for keeping track of a counter cache that lives in its own table. It works with Rails 4.1 and 4.2, and only MySQL.

Usage

For example, with User and Comment classes you may want to cache user.comments.size, but don't want to create comments_count on User.

class User < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :user, detached_counter_cache: true
end

You'll need to generate a migration that creates your counter cache table.

create_table :users_comments_counts, force: true do |t|
  t.integer :user_id, null: false
  t.integer :count, default: 0, null: false
end

Contributors

License

MIT License