From 63d81f588830cd4483fd7953474dff511f32eaba Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Tue, 16 May 2017 18:22:50 +0200 Subject: [PATCH 1/2] Add a helper for determining if IC model uses STI Add a helper for determining if IC model uses STI --- app/models/manager_refresh/inventory_collection.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index 4ceef9e5478..1daf98f7a38 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -378,6 +378,10 @@ def data_collection_finalized? data_collection_finalized end + def supports_sti? + @supports_sti_cache ||= model_class.column_names.include?("type") + end + def <<(inventory_object) unless data_index[inventory_object.manager_uuid] data_index[inventory_object.manager_uuid] = inventory_object From acaa987d32065d4ca48f6b761628476d970f4968 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Tue, 16 May 2017 18:24:34 +0200 Subject: [PATCH 2/2] Add checks to build method Add checks to build method, build should return nil if we cannot get the unique uuid of the InventoryObject and it should return exiting object if we have it. --- app/models/manager_refresh/inventory_collection.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index 1daf98f7a38..0d7a7d1ca86 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -480,6 +480,13 @@ def new_inventory_object(hash) def build(hash) hash = hash.merge(builder_params) inventory_object = new_inventory_object(hash) + + uuid = inventory_object.manager_uuid + # Each InventoryObject must be able to build an UUID, return nil if it can't + return nil if uuid.blank? + # Return existing InventoryObject if we have it + return data_index[uuid] if data_index[uuid] + # Store new InventoryObject and return it push(inventory_object) inventory_object end