2020-03-25 17:45:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# EventPriceCategory is the relation table between Event and PriceCategory.
|
2020-03-25 10:16:47 +01:00
|
|
|
class EventPriceCategory < ApplicationRecord
|
2016-08-24 12:30:48 +02:00
|
|
|
belongs_to :event
|
|
|
|
belongs_to :price_category
|
2016-08-25 14:13:30 +02:00
|
|
|
|
2022-12-28 17:51:27 +01:00
|
|
|
has_many :tickets, dependent: :restrict_with_error
|
|
|
|
has_many :cart_item_event_reservation_tickets, class_name: 'CartItem::EventReservationTicket', dependent: :restrict_with_error
|
2016-08-25 18:41:33 +02:00
|
|
|
|
2016-08-25 14:13:30 +02:00
|
|
|
validates :price_category_id, presence: true
|
|
|
|
validates :amount, presence: true
|
2017-03-02 18:34:55 +01:00
|
|
|
|
|
|
|
before_destroy :verify_no_associated_tickets
|
|
|
|
|
|
|
|
protected
|
2020-03-25 17:45:53 +01:00
|
|
|
|
2017-03-02 18:34:55 +01:00
|
|
|
def verify_no_associated_tickets
|
2020-04-28 10:05:28 +02:00
|
|
|
throw(:abort) unless tickets.count.zero?
|
2017-03-02 18:34:55 +01:00
|
|
|
end
|
2016-08-24 12:30:48 +02:00
|
|
|
end
|