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
Raw Normal View History

# 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.
2020-03-25 10:16:47 +01:00
class MachinesAvailability < ApplicationRecord
2016-03-23 18:39:41 +01:00
belongs_to :machine
belongs_to :availability
after_destroy :cleanup_availability
# when the MachinesAvailability is deleted (from Machine destroy cascade), we delete the corresponding
2017-02-13 14:38:28 +01:00
# availability if the deleted machine was the last of this availability slot, and the availability is not
2016-03-23 18:39:41 +01:00
# currently being destroyed.
def cleanup_availability
return if availability.destroying
return unless availability.machines_availabilities.empty?
availability.safe_destroy
2016-03-23 18:39:41 +01:00
end
end