Sha256: b6620a5c7065b771fe5e4ba276dbe666fe1ec8d9bdb8f7590c503cd31276e8d5
Contents?: true
Size: 796 Bytes
Versions: 32
Compression:
Stored size: 796 Bytes
Contents
class Usage < ApplicationRecord belongs_to :organization belongs_to :item, polymorphic: true belongs_to :parent_item, polymorphic: true scope :in_organization, ->(organization = Organization.current) { where(organization_id: organization.id) } before_save :set_slug before_destroy :destroy_children_usages! def self.destroy_all_where(query) where(query).destroy_all end def self.destroy_usages_for(record) destroy_all_where(parent_item: record) end def destroy_children_usages! item.structural_children.each { |child| Usage.destroy_all_where(parent_item: child, organization: organization) } end def index_children!(children) children.each { |it| it.index_usage! organization } end private def set_slug self.slug = item.slug end end
Version data entries
32 entries across 32 versions & 2 rubygems