Sha256: 29e3911694bef34da13b49b71f67156af8bc35705bb4152a21257416da895c0f

Contents?: true

Size: 437 Bytes

Versions: 3

Compression:

Stored size: 437 Bytes

Contents

module Comee
  module Core
    class Product < ApplicationRecord
      has_ancestry
      after_save :update_parent, if: proc { |product| product.parent && product.parent.leaf? }

      validates :code, presence: true, uniqueness: true
      validates :name, presence: true

      scope :leafs, -> { where(leaf: true) }

      def update_parent
        obj = parent
        obj.leaf = false
        obj.save!
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comee_core-0.1.43 app/models/comee/core/product.rb
comee_core-0.1.42 app/models/comee/core/product.rb
comee_core-0.1.41 app/models/comee/core/product.rb