2016-03-23 18:39:41 +01:00
|
|
|
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
|
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
|
|
|
|
unless availability.destroying
|
|
|
|
if availability.machines_availabilities.size == 0
|
|
|
|
availability.safe_destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|