From f9cacf82230774afd13c063cf7185950567c03e0 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 7 Nov 2018 20:20:16 -0500 Subject: [PATCH] update MiqReport::Search to include all columns When generating a query for a report, ensure that the columns necessary to join to other models are brought back. If a report needs additional columns for join models and the models are not part of the includes_for_find attribute, then ensure all columns including the join keys are in cols: attribute, and just the visible columns are in the col_order attribute --- app/models/miq_report/search.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/miq_report/search.rb b/app/models/miq_report/search.rb index 9dbd44e9740..6eeeed6d7ae 100644 --- a/app/models/miq_report/search.rb +++ b/app/models/miq_report/search.rb @@ -92,7 +92,19 @@ def paged_view_search(options = {}) search_options = options.merge(:class => db, :conditions => conditions, :include_for_find => includes) search_options.merge!(:limit => limit, :offset => offset, :order => order) if order - search_options[:extra_cols] = va_sql_cols if va_sql_cols.present? + + extra_cols = if includes + includes.keys.map do |rel| + if (rel = db_class.reflect_on_association(rel)) + # adding primary_key is probably overkill. + rel.macro == :belongs_to ? rel.foreign_key : db_class.primary_key + end + end.compact + else + [] + end + extra_cols += va_sql_cols if va_sql_cols.present? + search_options[:extra_cols] = extra_cols if extra_cols.present? if options[:parent] targets = get_parent_targets(options[:parent], options[:association] || options[:parent_method])