|
|
@ -32,8 +32,35 @@ class Report::GroupBy |
|
|
|
end.uniq |
|
|
|
end.uniq |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.select_fields(*fields) |
|
|
|
|
|
|
|
unless fields.empty? |
|
|
|
|
|
|
|
@select_fields ||= [] |
|
|
|
|
|
|
|
@select_fields += fields |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
@select_fields |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_fields |
|
|
|
|
|
|
|
if self.class.select_fields |
|
|
|
|
|
|
|
(parent ? parent.select_fields : []) + self.class.select_fields |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
group_fields |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## |
|
|
|
|
|
|
|
# @param [FalseClass, TrueClass] prefix Whether or not add a table prefix the field names |
|
|
|
|
|
|
|
# @return [Array<String,Symbol>] List of select fields corresponding to self and all parents' |
|
|
|
|
|
|
|
def all_select_fields(prefix = true) |
|
|
|
|
|
|
|
@all_select_fields ||= [] |
|
|
|
|
|
|
|
@all_select_fields[prefix ? 0 : 1] ||= begin |
|
|
|
|
|
|
|
fields = select_fields.reject { |c| c.blank? or c == 'base' } |
|
|
|
|
|
|
|
(parent ? parent.all_select_fields(prefix) : []) + (prefix ? with_table(fields) : fields) |
|
|
|
|
|
|
|
end.uniq |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def clear |
|
|
|
def clear |
|
|
|
@all_group_fields = nil |
|
|
|
@all_group_fields = @all_select_fields = nil |
|
|
|
super |
|
|
|
super |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -58,13 +85,8 @@ class Report::GroupBy |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def define_group(sql) |
|
|
|
def define_group(sql) |
|
|
|
fields = all_group_fields |
|
|
|
sql.select all_select_fields |
|
|
|
# fields usually are Strings which we want select and group_by |
|
|
|
sql.group_by all_group_fields |
|
|
|
# sometimes fields are arrays of the form [String,String], where |
|
|
|
|
|
|
|
# the fields.first is to select and where we have to group on field.last |
|
|
|
|
|
|
|
#TODO: differenciate between all_group_fields and all_select_fields |
|
|
|
|
|
|
|
sql.select fields.map {|field| field.is_a?(String) ? field : field.first} |
|
|
|
|
|
|
|
sql.group_by fields.map {|field| field.is_a?(String) ? field : field.last} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |