Fix referential integrity checks on polymorphic points associations

pull/325/merge
Rick Carlino 2017-05-22 07:53:31 -05:00
parent 8dac7cac76
commit 5798249045
4 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,7 @@
# etc.
class ToolSlot < ApplicationRecord
belongs_to :tool
has_one :point, as: :pointer, dependent: :destroy
has_one :point, as: :pointer#, dependent: :destroy
# has_many :sequence_dependencies, dependent: :destroy, as: :dependency
validates_uniqueness_of :tool,
allow_blank: true,

View File

@ -1,7 +1,9 @@
class AddPolymorphicConstraints < ActiveRecord::Migration[5.1]
def change
add_polymorphic_constraints :pointer, :tool_slots
add_polymorphic_constraints :pointer, :plants
add_polymorphic_constraints :pointer, :generic_pointers
add_polymorphic_constraints :pointer,
:points,
polymorphic_models: [:plant,
:tool_slot,
:generic_pointer]
end
end

View File

@ -2,10 +2,10 @@ unless Rails.env == "production"
ENV['MQTT_HOST'] = "blooper.io"
ENV['OS_UPDATE_SERVER'] = "http://blah.com"
ENV['FW_UPDATE_SERVER'] = "http://test.com"
Point.destroy_all
ToolSlot.destroy_all
Device.destroy_all
User.destroy_all
Point.destroy_all
Users::Create.run!(name: "Administrator",
email: "notos@notos.com",
password: "password123",

View File

@ -139,6 +139,6 @@ result.push(enum_type :LegalKindString, HASH[:nodes].map{ |x| x[:name] }.sort.un
result.push(enum_type :LegalSequenceKind, CeleryScriptSettingsBag::STEPS.sort)
result.push(enum_type :DataChangeType, CeleryScriptSettingsBag::ALLOWED_CHAGES)
result.push(enum_type :ResourceName, CeleryScriptSettingsBag::RESOURCE_NAME)
result.push(enum_type :PointType, CeleryScriptSettingsBag::ALLOWED_POINT_TYPE)
result.push(enum_type :PointType, CeleryScriptSettingsBag::ALLOWED_POINTER_TYPE)
puts result.join.gsub("\n\n\n", "\n")