Sha256: 067e8934014eff327fa427a19b8e77baf4021bab05831005c87ab3aaa7c21ff1
Contents?: true
Size: 937 Bytes
Versions: 54
Compression:
Stored size: 937 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! before_destroy :delete_associated_indicators! 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 delete_associated_indicators! Indicator.delete_all_for!(item, organization) end def set_slug self.slug = item.slug end end
Version data entries
54 entries across 54 versions & 2 rubygems