2020-03-25 17:45:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# PriceCategory is a way to segment prices for an Event.
|
|
|
|
# By default, each Events have a standard price but you may want, for example, to define a reduced fare for students,
|
|
|
|
# and another reduced fare for children under 8. Each of these prices are defined in an EventPriceCategory.
|
|
|
|
# You can choose to use each PriceCategory or not, for each Event you create.
|
2020-03-25 10:16:47 +01:00
|
|
|
class PriceCategory < ApplicationRecord
|
2016-08-24 12:30:48 +02:00
|
|
|
has_many :event_price_category
|
|
|
|
has_many :events, through: :event_price_categories
|
|
|
|
|
2020-03-25 17:45:53 +01:00
|
|
|
validates :name, presence: true
|
|
|
|
validates :name, uniqueness: { case_sensitive: false }
|
|
|
|
validates :conditions, presence: true
|
2016-08-24 16:52:37 +02:00
|
|
|
|
2016-08-24 12:30:48 +02:00
|
|
|
def safe_destroy
|
2020-03-25 17:45:53 +01:00
|
|
|
if event_price_category.count.zero?
|
2016-08-24 12:30:48 +02:00
|
|
|
destroy
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|