Permalink
Browse files

arel columns can be used for grouping so that "weird" column names ar…

…e usable
  • Loading branch information...
1 parent ca71bb8 commit 0803d7a93b4a67340719eedddcc1746414fc2405 @tenderlove tenderlove committed Nov 15, 2012
@@ -335,6 +335,10 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
# column_alias_for("count(*)") # => "count_all"
# column_alias_for("count", "id") # => "count_id"
def column_alias_for(keys)
+ if keys.respond_to? :name
+ keys = "#{keys.relation.name}.#{keys.name}"
+ end
+
table_name = keys.to_s.downcase
table_name.gsub!(/\*/, 'all')
table_name.gsub!(/\W+/, ' ')
@@ -616,6 +616,12 @@ def test_non_valid_identifier_column_name
assert_equal 'value2', weird.read_attribute('a$b')
end
+ def test_group_weirds_by_from
+ Weird.create('a$b' => 'value', :from => 'aaron')
+ count = Weird.group(Weird.arel_table[:from]).count
+ assert_equal 1, count['aaron']
+ end
+
def test_attributes_on_dummy_time
# Oracle, and Sybase do not have a TIME datatype.
return true if current_adapter?(:OracleAdapter, :SybaseAdapter)
@@ -770,6 +770,7 @@ def create_table(*args, &block)
end
create_table :weirds, :force => true do |t|
t.string 'a$b'
+ t.string 'from'
end
except 'SQLite' do

0 comments on commit 0803d7a

Please sign in to comment.