No commit activity in last 3 years
No release in over 3 years
Give condition when to increment/decrement counter cache.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
~> 10.0
= 3.0.2

Runtime

 Project Readme

ConditionalCounterCache

Give condition when to increment/decrement counter cache.

Usage

Customize condition via :counter_cache option:

class Tagging < ActiveRecord::Base
  belongs_to :item
  belongs_to :tag, counter_cache: { condition: -> { !item.private? } }
end

Other examples:

belongs_to :tag, counter_cache: true
belongs_to :tag, counter_cache: "items_count"
belongs_to :tag, counter_cache: { condition: -> { !item.private? } }
belongs_to :tag, counter_cache: { condition: -> :your_favorite_method_name }
belongs_to :tag, counter_cache: { column_name: "items_count" }
belongs_to :tag, counter_cache: { column_name: "items_count", condition: -> { !item.private? } }

See also