diff --git a/app/models/host.rb b/app/models/host.rb index 1e849eebbee..4815aa037f6 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -1750,11 +1750,19 @@ def openstack_host? # TODO: This doesn't belong here end def writable_storages - storages.where(:host_storages => {:read_only => [false, nil]}) + if host_storages.loaded? && host_storages.all? { |hs| hs.association(:storage).loaded? } + host_storages.reject(&:read_only).map(&:storage) + else + storages.where(:host_storages => {:read_only => [false, nil]}) + end end def read_only_storages - storages.where(:host_storages => {:read_only => true}) + if host_storages.loaded? && host_storages.all? { |hs| hs.association(:storage).loaded? } + host_storages.select(&:read_only).map(&:storage) + else + storages.where(:host_storages => {:read_only => true}) + end end def archived? diff --git a/app/models/miq_request_workflow.rb b/app/models/miq_request_workflow.rb index 881b90542a0..e6526f3af28 100644 --- a/app/models/miq_request_workflow.rb +++ b/app/models/miq_request_workflow.rb @@ -1050,7 +1050,7 @@ def allowed_storages(_options = {}) rails_logger('allowed_storages', 0) st = Time.now - MiqPreloader.preload(hosts, :storages) + MiqPreloader.preload(hosts, :storages => {}, :host_storages => :storage) storages = hosts.each_with_object({}) do |host, hash| host.writable_storages.each { |s| hash[s.id] = s }