QUick fix- more investigation needed

pull/1492/head
Rick Carlino 2019-10-04 11:26:55 -05:00
parent fad467530c
commit 8dc1be228b
3 changed files with 9 additions and 0 deletions

View File

@ -83,6 +83,9 @@ module Api
def clean_expired_farm_events
FarmEvents::CleanExpired.run!(device: current_device)
# TODO: Why does this even exist? This should
# be fixable via foreign key constraints. - RC 4 OCT 19
Fragment.remove_old_fragments_for_device(current_device)
end
# Rails 5 params are no longer simple hashes. This was for security reasons.

View File

@ -87,4 +87,8 @@ class Fragment < ApplicationRecord
def broadcast?
false
end
def self.remove_old_fragments_for_device(dev)
dev.fragments.select { |x| x.owner == nil }.map { |x| x.destroy! }
end
end

View File

@ -9,6 +9,7 @@ module PointGroups
end
def validate
Fragment.remove_old_fragments_for_device(device)
add_error "in_use", :in_use, human_readable_error if in_use?
end
@ -53,6 +54,7 @@ module PointGroups
@fragment_users = Fragment
.find(relevant_fragments)
.map(&:owner)
.compact # Referential integrity issues??? - RC 4 oct 19
.map { |x| "#{x.class} '#{x.fancy_name}'" }
end
end