From 7e6ab4f744a6d04ec8964008b7b84b1cc8925514 Mon Sep 17 00:00:00 2001 From: Moti Asayag Date: Sun, 3 Sep 2017 19:46:03 +0300 Subject: [PATCH] Apply distinct on LAN/switch selection Several hosts might be connected to the same switch, sharing the same LAN. Therefore it is required to apply 'DISTINCT' on the result of the join of these tables. --- .../manageiq/providers/infra_manager.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/manageiq/providers/infra_manager.rb b/app/models/manageiq/providers/infra_manager.rb index f474551591a..47a0ddc840c 100644 --- a/app/models/manageiq/providers/infra_manager.rb +++ b/app/models/manageiq/providers/infra_manager.rb @@ -7,17 +7,17 @@ class InfraManager < BaseManager include AvailabilityMixin - has_many :host_hardwares, :through => :hosts, :source => :hardware - has_many :host_operating_systems, :through => :hosts, :source => :operating_system - has_many :host_storages, :through => :hosts - has_many :host_switches, :through => :hosts - has_many :host_networks, :through => :hosts, :source => :networks - has_many :snapshots, :through => :vms_and_templates - has_many :operating_systems, :through => :vms_and_templates - has_many :switches, :through => :hosts - has_many :lans, :through => :hosts - has_many :networks, :through => :hardwares - has_many :guest_devices, :through => :hardwares + has_many :host_hardwares, :through => :hosts, :source => :hardware + has_many :host_operating_systems, :through => :hosts, :source => :operating_system + has_many :host_storages, :through => :hosts + has_many :host_switches, :through => :hosts + has_many :host_networks, :through => :hosts, :source => :networks + has_many :snapshots, :through => :vms_and_templates + has_many :operating_systems, :through => :vms_and_templates + has_many :switches, -> { distinct }, :through => :hosts + has_many :lans, -> { distinct }, :through => :hosts + has_many :networks, :through => :hardwares + has_many :guest_devices, :through => :hardwares class << model_name define_method(:route_key) { "ems_infras" }