Module: SubjModels::OrderItemModule

Includes:
TypesSupport::ItemTypes, ValuesChecker
Defined in:
lib/subj_models/order_item.rb

Constant Summary

Constants included from TypesSupport::ItemTypes

TypesSupport::ItemTypes::EVENT, TypesSupport::ItemTypes::ITEM_TYPES, TypesSupport::ItemTypes::PRODUCT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValuesChecker

#check_string_for_int

Class Method Details

.included(including_class) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/subj_models/order_item.rb', line 11

def self.included(including_class)

  including_class.class_eval do

    include SubjModels::ComprisingExternalId

    before_destroy :decrease_nomenclature_popularity
    after_create :increase_nomenclature_popularity

    enum item_type: ITEM_TYPES

    belongs_to :order
    belongs_to :event
    belongs_to :nomenclature_variety
    belongs_to :nomenclature

    validates :item_type, presence: true, inclusion: { in: item_types.keys }
    validates :item_price, :item_count, presence: true

    scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }

  end

end

Instance Method Details

#item_type=(value) ⇒ Object



40
41
42
# File 'lib/subj_models/order_item.rb', line 40

def item_type=(value)
  super(check_string_for_int(value))
end

#to_sObject



36
37
38
# File 'lib/subj_models/order_item.rb', line 36

def to_s
  id.to_s # TODO
end