-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathworkshop_variation.rb
More file actions
28 lines (22 loc) · 1013 Bytes
/
workshop_variation.rb
File metadata and controls
28 lines (22 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class WorkshopVariation < ApplicationRecord
belongs_to :workshop
belongs_to :created_by, class_name: 'User', optional: true
has_many :bookmarks, as: :bookmarkable, dependent: :destroy
# Image associations
has_many :images, as: :owner, dependent: :destroy
has_one :main_image, -> { where(type: "Images::MainImage") },
as: :owner, class_name: "Images::MainImage", dependent: :destroy
has_many :gallery_images, -> { where(type: "Images::GalleryImage") },
as: :owner, class_name: "Images::GalleryImage", dependent: :destroy
validates :name, presence: true, uniqueness: { scope: :workshop_id, case_sensitive: false }
accepts_nested_attributes_for :main_image, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :gallery_images, allow_destroy: true, reject_if: :all_blank
scope :active, -> { where(inactive: false) }
delegate :windows_type, to: :workshop
def description
code # TODO - rename this field
end
def title
name
end
end