Permalink
Browse files

Merge pull request #93 from iwiznia/sql_select_option

Activerecord driver, adds the AS part of the select automatically
  • Loading branch information...
2 parents 7e30b2f + 9be34d3 commit f234731e309df0262f3789a69e46f41006c552ef @bogdan committed Mar 7, 2014
View
@@ -172,7 +172,7 @@ def inherited(child_class) #:nodoc:
module InstanceMethods
def assets
- driver.append_column_queries(super, columns.map(&:query).compact)
+ driver.append_column_queries(super, columns.select(&:query))
end
# Returns <tt>Array</tt> of human readable column names. See also "Localization" section
@@ -31,6 +31,7 @@ def append_column_queries(assets, columns)
if assets.select_values.empty?
assets = assets.select(Arel.respond_to?(:star) ? assets.klass.arel_table[Arel.star] : "#{assets.quoted_table_name}.*")
end
+ columns = columns.map {|c| "#{c.query} AS #{c.name}"}
assets = assets.select(*columns)
end
assets
@@ -88,7 +88,7 @@
scope {Entry}
filter(:name)
column(:id)
- column(:sum_group_id, 'sum(group_id) sum_group_id')
+ column(:sum_group_id, 'sum(group_id)')
end
report.assets.first.sum_group_id.should == group.id
end
@@ -17,8 +17,8 @@
end
it "should support append_column_queries" do
- scope = subject.append_column_queries(Entry.scoped, ['sum(entries.group_id) sum_group_id'])
+ scope = subject.append_column_queries(Entry.scoped, [Datagrid::Columns::Column.new(SimpleReport, :sum_group_id, 'sum(entries.group_id)')])
scope.select_values.length.should == 2
- scope.select_values.should == ["#{Entry.quoted_table_name}.*", 'sum(entries.group_id) sum_group_id']
+ scope.select_values.should == ["#{Entry.quoted_table_name}.*", 'sum(entries.group_id) AS sum_group_id']
end
end

0 comments on commit f234731

Please sign in to comment.