1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/models/machines_availability.rb

21 lines
750 B
Ruby

# frozen_string_literal: true
# MachinesAvailability is the relation table between a Machine and an Availability.
# It defines periods in the agenda, when the given machine can be reserved by members.
class MachinesAvailability < ApplicationRecord
belongs_to :machine
belongs_to :availability
after_destroy :cleanup_availability
# when the MachinesAvailability is deleted (from Machine destroy cascade), we delete the corresponding
# availability if the deleted machine was the last of this availability slot, and the availability is not
# currently being destroyed.
def cleanup_availability
return if availability.destroying
return unless availability.machines_availabilities.empty?
availability.safe_destroy
end
end