I am using the counter_culture gem to cache my counts. Here are the models:
User model
has_many :memberships, dependent: :destroy
Membership model
has_many :authorables, dependent: :destroy
has_many :posts, through: :authorables
Post model
has_many :authorables, dependent: :destroy
has_many :authors, through: :authorables, source: :membership
Authorable model
belongs_to :membership
belongs_to :post
counter_culture :post, column_name: "authors_count"
As you can see, I am caching the authors_count on the post model.
When I update the post, post.update(authors: [membership]) the counter increments by 1, but when I try and remove the authors post.update(authors: []), the counter does not decrement.
Is there a way to fix it?