Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #93 from iwiznia/sql_select_option

Activerecord driver, adds the AS part of the select automatically
  • Loading branch information...
commit f234731e309df0262f3789a69e46f41006c552ef 2 parents 7e30b2f + 9be34d3
@bogdan authored
View
2  lib/datagrid/columns.rb
@@ -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
View
1  lib/datagrid/drivers/active_record.rb
@@ -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
View
2  spec/datagrid/columns_spec.rb
@@ -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
View
4 spec/datagrid/drivers/active_record_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.