2020-03-25 17:45:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# SpacesAvailability is the relation table between a Space and an Availability.
|
|
|
|
# It defines periods in the agenda, when the given space can be reserved by members.
|
2020-03-25 10:16:47 +01:00
|
|
|
class SpacesAvailability < ApplicationRecord
|
2017-02-13 14:38:28 +01:00
|
|
|
belongs_to :space
|
|
|
|
belongs_to :availability
|
|
|
|
after_destroy :cleanup_availability
|
|
|
|
|
|
|
|
# when the SpacesAvailability is deleted (from Space destroy cascade), we delete the corresponding
|
|
|
|
# availability. We don't use 'dependent: destroy' as we need to prevent conflicts if the destroy came from
|
|
|
|
# the Availability destroy cascade.
|
|
|
|
def cleanup_availability
|
2020-03-25 17:45:53 +01:00
|
|
|
return unless availability.destroying
|
|
|
|
|
|
|
|
availability.safe_destroy
|
2017-02-13 14:38:28 +01:00
|
|
|
end
|
|
|
|
end
|