Sha256: 7dacdf9c407b1a7a3b6fcfa302e991f37085a4331d28af040c21770ffd71bba5

Contents?: true

Size: 598 Bytes

Versions: 37

Compression:

Stored size: 598 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the features needed when you want a model to have a category.
  module HasCategory
    extend ActiveSupport::Concern

    included do
      has_one :categorization, as: :categorizable
      has_one :category, through: :categorization

      validate :category_belongs_to_organization

      private

      def category_belongs_to_organization
        return unless category
        errors.add(:category, :invalid) unless feature.categories.where(id: category.id).exists?
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
decidim-core-0.9.3 lib/decidim/has_category.rb
decidim-core-0.9.2 lib/decidim/has_category.rb
decidim-core-0.9.1 lib/decidim/has_category.rb
decidim-core-0.9.0 lib/decidim/has_category.rb
decidim-core-0.8.4 lib/decidim/has_category.rb
decidim-core-0.8.3 lib/decidim/has_category.rb
decidim-core-0.8.2 lib/decidim/has_category.rb
decidim-core-0.8.1 lib/decidim/has_category.rb
decidim-core-0.8.0 lib/decidim/has_category.rb
decidim-core-0.7.4 lib/decidim/has_category.rb
decidim-core-0.7.3 lib/decidim/has_category.rb
decidim-core-0.7.2 lib/decidim/has_category.rb
decidim-core-0.7.1 lib/decidim/has_category.rb
decidim-core-0.7.0 lib/decidim/has_category.rb
decidim-core-0.6.8 lib/decidim/has_category.rb
decidim-0.6.8 decidim-core/lib/decidim/has_category.rb
decidim-core-0.6.7 lib/decidim/has_category.rb
decidim-0.6.7 decidim-core/lib/decidim/has_category.rb
decidim-core-0.6.6 lib/decidim/has_category.rb
decidim-0.6.6 decidim-core/lib/decidim/has_category.rb