From 4f83aa7ddab43f60044aa4b0d81e13410d38f8fa Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 16 Jan 2018 18:14:59 -0500 Subject: [PATCH 1/3] AssetDetail model should be singular --- app/models/{asset_details.rb => asset_detail.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/models/{asset_details.rb => asset_detail.rb} (74%) diff --git a/app/models/asset_details.rb b/app/models/asset_detail.rb similarity index 74% rename from app/models/asset_details.rb rename to app/models/asset_detail.rb index 7cc94ca69e2..f1bd3963868 100644 --- a/app/models/asset_details.rb +++ b/app/models/asset_detail.rb @@ -1,4 +1,4 @@ -class AssetDetails < ApplicationRecord +class AssetDetail < ApplicationRecord include NewWithTypeStiMixin acts_as_miq_taggable From 5414e75109af950e6b5abeab9e23d37153309647 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 16 Jan 2018 18:16:27 -0500 Subject: [PATCH 2/3] The columns are resource_type and resource_id --- app/models/asset_detail.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/asset_detail.rb b/app/models/asset_detail.rb index f1bd3963868..ad95e51a4e2 100644 --- a/app/models/asset_detail.rb +++ b/app/models/asset_detail.rb @@ -3,5 +3,5 @@ class AssetDetail < ApplicationRecord acts_as_miq_taggable - belongs_to :physical_server, :polymorphic => true + belongs_to :resource, :polymorphic => true end From e7fbe826e8ff24107a9e28808c7da6acd4f20b99 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 16 Jan 2018 18:19:29 -0500 Subject: [PATCH 3/3] Update associations and factory --- app/models/ems_refresh/save_inventory_physical_infra.rb | 6 +++--- app/models/physical_server.rb | 2 +- spec/factories/asset_details.rb | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/ems_refresh/save_inventory_physical_infra.rb b/app/models/ems_refresh/save_inventory_physical_infra.rb index c1185f8ad39..ab4f01a1671 100644 --- a/app/models/ems_refresh/save_inventory_physical_infra.rb +++ b/app/models/ems_refresh/save_inventory_physical_infra.rb @@ -47,7 +47,7 @@ def save_physical_servers_inventory(ems, hashes, target = nil) [] end - child_keys = [:computer_system, :asset_details, :hosts] + child_keys = [:computer_system, :asset_detail, :hosts] save_inventory_multi(ems.physical_servers, hashes, deletes, [:ems_ref], child_keys) store_ids_for_new_records(ems.physical_servers, hashes, :ems_ref) end @@ -69,8 +69,8 @@ def save_customization_scripts_inventory(ems, hashes, target = nil) # # Saves asset details information of a resource # - def save_asset_details_inventory(parent, hash) + def save_asset_detail_inventory(parent, hash) return if hash.nil? - save_inventory_single(:asset_details, parent, hash) + save_inventory_single(:asset_detail, parent, hash) end end diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index fc5dee64c69..c937015716b 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -22,7 +22,7 @@ class PhysicalServer < ApplicationRecord has_one :computer_system, :as => :managed_entity, :dependent => :destroy has_one :hardware, :through => :computer_system has_one :host, :inverse_of => :physical_server - has_one :asset_details, :as => :resource, :dependent => :destroy + has_one :asset_detail, :as => :resource, :dependent => :destroy scope :with_hosts, -> { where("physical_servers.id in (select hosts.physical_server_id from hosts)") } diff --git a/spec/factories/asset_details.rb b/spec/factories/asset_details.rb index 7d8180db93a..a0e160b7047 100644 --- a/spec/factories/asset_details.rb +++ b/spec/factories/asset_details.rb @@ -1,4 +1,3 @@ FactoryGirl.define do - factory :asset_details do - end + factory :asset_detail end