Sha256: e7a43bdaafc24e3171d4f3c2864861c3eb97fa5c732d2145257a1d3455e4cdaa

Contents?: true

Size: 752 Bytes

Versions: 13

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Budgets
    # The data store for a LineItem in the Decidim::Budgets component. It describes an
    # association between an order and a project.
    class LineItem < Budgets::ApplicationRecord
      belongs_to :order, class_name: Decidim::Budgets::Order, foreign_key: "decidim_order_id"
      belongs_to :project, class_name: Decidim::Budgets::Project, foreign_key: "decidim_project_id"

      validates :order, presence: true, uniqueness: { scope: :project }
      validates :project, presence: true
      validate :same_feature

      def same_feature
        return unless order && project
        errors.add(:order, :invalid) unless order.feature == project.feature
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
decidim-budgets-0.1.0 app/models/decidim/budgets/line_item.rb
decidim-0.1.0 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-budgets-0.0.8.1 app/models/decidim/budgets/line_item.rb
decidim-0.0.8.1 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-budgets-0.0.7 app/models/decidim/budgets/line_item.rb
decidim-0.0.7 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-budgets-0.0.6 app/models/decidim/budgets/line_item.rb
decidim-0.0.6 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-budgets-0.0.5 app/models/decidim/budgets/line_item.rb
decidim-0.0.5 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-0.0.4 decidim-budgets/app/models/decidim/budgets/line_item.rb
decidim-budgets-0.0.3 app/models/decidim/budgets/line_item.rb
decidim-0.0.3 decidim-budgets/app/models/decidim/budgets/line_item.rb