Sha256: ab7fa696df25e383f0ae11e5293c24ecd2d4bc77bf879d015162f934ca0ddb7e
Contents?: true
Size: 1.31 KB
Versions: 8
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Decidim # Areas are used in Assemblies to help users know which is # the Area of a participatory space. class Area < ApplicationRecord include Traceable include Loggable belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization", inverse_of: :areas belongs_to :area_type, foreign_key: "area_type_id", class_name: "Decidim::AreaType", inverse_of: :areas, optional: true validates :name, :organization, presence: true validates :name, uniqueness: { scope: [:organization, :area_type] } before_destroy :abort_if_dependencies def self.log_presenter_class_for(_log) Decidim::AdminLog::AreaPresenter end def translated_name Decidim::AreaPresenter.new(self).translated_name end def has_dependencies? Decidim.participatory_space_registry.manifests.any? do |manifest| manifest .participatory_spaces .call(organization) .any? do |space| space.respond_to?(:area) && space.decidim_area_id == id end end end # used on before_destroy def abort_if_dependencies throw(:abort) if has_dependencies? end end end
Version data entries
8 entries across 8 versions & 1 rubygems