diff --git a/app/models/miq_report/search.rb b/app/models/miq_report/search.rb index 9dbd44e97406..8ce8dd0fb370 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 over kill. + rel.foreign_key if rel.macro == :belongs_to ? : 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 options[:parent] targets = get_parent_targets(options[:parent], options[:association] || options[:parent_method])