Skip to content

kongregate/detached_counter_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

counter cache that lives in its own table

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages