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
|
# File 'lib/subj_models/brand.rb', line 8
def self.included(including_class)
including_class.class_eval do
include SubjModels::SharedScopes
include SubjModels::ComprisingExternalId
has_many :user_videos, dependent: :destroy
has_many :brand_lines, dependent: :destroy
has_many :nomenclatures
has_many :videos
has_many :events
has_and_belongs_to_many :users
has_and_belongs_to_many :action_banners
belongs_to :content_block1, class_name: "ContentBlock"
belongs_to :content_block2, class_name: "ContentBlock"
belongs_to :content_block3, class_name: "ContentBlock"
belongs_to :document_file
before_validation :set_first_letter, if: :name_changed?
validates :name, presence: true
scope :in_index_list, -> condition { where(show_on_index: condition) }
scope :in_recommended_list, -> condition { where(is_recommended: condition) }
scope :category_id, -> (category_id) do
return all if category_id.blank?
joins(brand_lines: [{ nomenclatures: :category}]).where('categories.id' => category_id)
end
scope :by_first_letters, -> (by_first_letters) do
unless by_first_letters.blank?
where(first_letter: by_first_letters)
end
end
scope :has_events, -> do
joins(events: :event_schedule).where('event_schedules.event_date >= ?', DateTime.now.beginning_of_day).uniq
end
end
end
|