Skip to content

Commit

Permalink
Merge pull request #14294 from kbrock/report_includes_cols
Browse files Browse the repository at this point in the history
Report includes cols
  • Loading branch information
gtanzillo authored Apr 11, 2017
2 parents 4f7363a + 89ac78a commit c5956c8
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,42 +93,27 @@ def invent_includes
end
end

def include_as_hash(includes = include, klass = nil)
if klass.nil?
klass = db_class
result = {}
if cols && klass.respond_to?(:virtual_attribute?)
cols.each do |c|
result[c.to_sym] = {} if klass.virtual_attribute?(c) && !klass.attribute_supported_by_sql?(c)
end
def include_as_hash(includes = include, klass = db_class, klass_cols = cols)
result = {}
if klass_cols && klass && klass.respond_to?(:virtual_attribute?)
klass_cols.each do |c|
result[c.to_sym] = {} if klass.virtual_attribute?(c) && !klass.attribute_supported_by_sql?(c)
end
end

if includes.kind_of?(Hash)
result ||= {}
includes.each do |k, v|
k = k.to_sym
if k == :managed
result[:tags] = {}
else
assoc_reflection = klass.reflect_on_association(k)
assoc_klass = assoc_reflection.nil? ? nil : (assoc_reflection.options[:polymorphic] ? k : assoc_reflection.klass)

if v.nil? || v["include"].blank?
result[k] = {}
elsif assoc_klass
result[k] = include_as_hash(v["include"], assoc_klass)
end
assoc_klass = (assoc_reflection.options[:polymorphic] ? k : assoc_reflection.klass) if assoc_reflection

if assoc_klass && assoc_klass.respond_to?(:virtual_attribute?) && v["columns"]
v["columns"].each do |c|
result[k][c.to_sym] = {} if assoc_klass.virtual_attribute?(c) && !assoc_klass.attribute_supported_by_sql?(c)
end
end
result[k] = include_as_hash(v && v["include"], assoc_klass, v && v["columns"])
end
end
elsif includes.kind_of?(Array)
result ||= {}
includes.each { |i| result[i.to_sym] = {} }
end

Expand Down

0 comments on commit c5956c8

Please sign in to comment.