1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/machines_availability.rb
2017-02-13 14:38:28 +01:00

17 lines
560 B
Ruby

class MachinesAvailability < ActiveRecord::Base
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
unless availability.destroying
if availability.machines_availabilities.size == 0
availability.safe_destroy
end
end
end
end