diff --git a/app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb b/app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb index 3e20deef03f..a9cbe644599 100644 --- a/app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb +++ b/app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb @@ -165,17 +165,21 @@ def vm_and_miq_template_ancestry_save_block # Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj| - unless x.data[:genealogy_parent].nil? - genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) - obj[x.id] = genealogy_parent_id if genealogy_parent_id - end + next if x.data[:genealogy_parent].nil? + + genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) + next if genealogy_parent_id.nil? || genealogy_parent_id == x.id + + obj[x.id] = genealogy_parent_id end miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj| - unless x.data[:genealogy_parent].nil? - genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) - obj[x.id] = genealogy_parent_id if genealogy_parent_id - end + next if x.data[:genealogy_parent].nil? + + genealogy_parent_id = x.data[:genealogy_parent].load.try(:id) + next if genealogy_parent_id.nil? || genealogy_parent_id == x.id + + obj[x.id] = genealogy_parent_id end ActiveRecord::Base.transaction do