7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/subj_models/nomenclature_price.rb', line 7
def self.included(including_class)
including_class.class_eval do
include SubjModels::ComprisingExternalId
belongs_to :nomenclature, touch: true
belongs_to :nomenclature_variety
belongs_to :price_type
belongs_to :quality
belongs_to :measure_unit
belongs_to :event
has_many :order_items
validates :current_price, presence: true
scope :nomenclature_id, -> (nomenclature_id) { parent_id_scope("nomenclature", nomenclature_id) }
scope :belongs_to_nomenclature, -> (nomenclature_id) do
where(nomenclature_id: nomenclature_id).union(joins(:nomenclature_variety).where("nomenclature_varieties.nomenclature_id" => nomenclature_id))
end
end
end
|