module Elabs class ArticlesTag < ApplicationRecord self.table_name = 'articles_tags' belongs_to :article belongs_to :tag after_create :increment_counter_cache after_destroy :decrement_counter_cache private def increment_counter_cache tag.increment! :articles_count if article.publicly_visible? end def decrement_counter_cache tag.decrement! :articles_count if article.publicly_visible? end end end