diff --git a/app/models/load_balancer_pool.rb b/app/models/load_balancer_pool.rb index 76f1c7489ca..91da65474b3 100644 --- a/app/models/load_balancer_pool.rb +++ b/app/models/load_balancer_pool.rb @@ -8,6 +8,7 @@ class LoadBalancerPool < ApplicationRecord has_many :load_balancer_listener_pools, :dependent => :destroy has_many :load_balancer_listeners, :through => :load_balancer_listener_pools + has_many :load_balancers, :through => :load_balancer_listeners has_many :load_balancer_pool_member_pools, :dependent => :destroy has_many :load_balancer_pool_members, :through => :load_balancer_pool_member_pools diff --git a/app/models/manager_refresh/inventory_collection_default/network_manager.rb b/app/models/manager_refresh/inventory_collection_default/network_manager.rb index 8f2246f6b27..f30223c6cdb 100644 --- a/app/models/manager_refresh/inventory_collection_default/network_manager.rb +++ b/app/models/manager_refresh/inventory_collection_default/network_manager.rb @@ -116,7 +116,10 @@ def load_balancer_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_pools.where(:ems_ref => manager_uuids) + inventory_collection.parent.load_balancer_pools + .joins(:load_balancers) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -135,9 +138,14 @@ def load_balancer_pool_members(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_members - .joins(:load_balancer_pool_member_pools => :load_balancler_pool) - .where(:load_balancer_pool_member_pools => {'load_balancer_pools' => {:ems_ref => manager_uuids}}) - .distinct + .joins(:load_balancer_pool_member_pools => [:load_balancer_pool => :load_balancers]) + .where(:load_balancer_pool_member_pools => { + 'load_balancer_pools' => { + 'load_balancers' => { + :ems_ref => manager_uuids + } + } + }).distinct end attributes.merge!(extra_attributes) @@ -154,8 +162,8 @@ def load_balancer_pool_member_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } inventory_collection.parent.load_balancer_pool_member_pools - .references(:load_balancer_pools) - .where(:load_balancer_pools => {:ems_ref => manager_uuids}) + .joins(:load_balancer_pool => :load_balancers) + .where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}}) .distinct end @@ -175,9 +183,10 @@ def load_balancer_listeners(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_listeners.joins(:load_balancer).where( - :load_balancers => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_listeners + .joins(:load_balancer) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -193,9 +202,10 @@ def load_balancer_listener_pools(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_listener_pools.joins(:load_balancer_pool).where( - :load_balancer_pools => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_listener_pools + .joins(:load_balancer_pool => :load_balancers) + .where(:load_balancer_pools => {'load_balancers' => {:ems_ref => manager_uuids}}) + .distinct end attributes.merge!(extra_attributes) @@ -213,7 +223,10 @@ def load_balancer_health_checks(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_health_checks.where(:ems_ref => manager_uuids) + inventory_collection.parent.load_balancer_health_checks + .joins(:load_balancer) + .where(:load_balancers => {:ems_ref => manager_uuids}) + .distinct end attributes.merge!(extra_attributes) @@ -229,9 +242,10 @@ def load_balancer_health_check_members(extra_attributes = {}) attributes[:targeted_arel] = lambda do |inventory_collection| manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } - inventory_collection.parent.load_balancer_health_check_members.references(:load_balancer_health_checks).where( - :load_balancer_health_checks => {:ems_ref => manager_uuids} - ) + inventory_collection.parent.load_balancer_health_check_members + .joins(:load_balancer_health_check => :load_balancer) + .where(:load_balancer_health_checks => {'load_balancers' => {:ems_ref => manager_uuids}}) + .distinct end attributes.merge!(extra_attributes)