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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/subj_models/event.rb', line 7
def self.included(including_class)
including_class.class_eval do
include SubjModels::ComprisingExternalId
belongs_to :manager
belongs_to :event_type
belongs_to :nomenclature
belongs_to :document_file
belongs_to :brand
has_one :event_schedule
has_one :nomenclature_price
has_many :order_items
has_many :event_bookings
has_and_belongs_to_many :user_specializations
has_and_belongs_to_many :nomenclatures
validates :document_file, :title, presence: true
scope :from_today, -> {
Event.joins(:event_schedule).where('event_schedules.event_date >= ?', DateTime.now.beginning_of_day )
.includes(:event_schedule).order( 'event_schedules.event_date ASC' ).uniq
}
scope :where_nomenclature_ids, -> (ids) do
joins(:nomenclatures).where(nomenclatures: {id: ids})
end
scope :office_ids, -> (ids) do
joins(event_schedule: [:office]).where(event_schedule: { office: {id: ids}})
end
scope :type_ids, -> (ids) do
joins(:event_type).where(event_type: {id: ids})
end
scope :brand_ids, -> (ids) do
joins(:brand).where(brand: { id: ids})
end
scope :only_free, -> do
joins(:event_schedule).where(event_schedule: { is_free: true } )
end
scope :specialities_ids, -> (ids) do
joins(:user_specializations).where(user_specializations: { id: ids})
end
scope :date_range, -> (date) do
joins(:event_schedule)
.where(event_schedule: { event_date: DateTime.parse(date['from']).beginning_of_day..DateTime.parse(date['to']).end_of_day } )
end
scope :today_events, -> {
includes(:event_schedule).where(event_schedule: { event_date: DateTime.now.beginning_of_day..DateTime.now.end_of_day } )
}
scope :is_public, -> { where(is_public: true) }
end
end
|