Sha256: c383ac9793a081acc9671620ed063d666f7bd7b8932a6ce126e1c28df162b767

Contents?: true

Size: 639 Bytes

Versions: 9

Compression:

Stored size: 639 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Initiatives
    module HasArea
      extend ActiveSupport::Concern

      included do
        belongs_to :area,
                   foreign_key: "decidim_area_id",
                   class_name: "Decidim::Area",
                   optional: true

        delegate :areas, to: :organization

        validate :area_belongs_to_organization
      end

      private

      def area_belongs_to_organization
        return unless area && organization

        errors.add(:area, :invalid) unless areas.where(id: area.id).exists?
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-initiatives-0.23.6 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.5 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.4 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.3 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.2 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.1 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.1.rc1 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.23.0 app/models/concerns/decidim/initiatives/has_area.rb
decidim-initiatives-0.22.0 app/models/concerns/decidim/initiatives/has_area.rb