module Elabs class AlbumsUpload < ApplicationRecord self.table_name = 'albums_uploads' belongs_to :album belongs_to :upload after_create :increment_counter_cache after_destroy :decrement_counter_cache private def increment_counter_cache album.increment! :uploads_count if upload.publicly_visible? end def decrement_counter_cache album.decrement! :uploads_count if upload.publicly_visible? end end end