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])