Permalink
Browse files

fix time typcasting on group counts in PG

  • Loading branch information...
tenderlove committed Dec 29, 2012
1 parent 8faf2b3 commit 160af90ac02a566d4d56bed6d7fa5e5026375a70
@@ -274,7 +274,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
column_alias_for(field)
}
group_columns = group_aliases.zip(group_fields).map { |aliaz,field|
- [aliaz, column_for(field)]
+ [aliaz, field]
}
group = group_fields
@@ -314,7 +314,10 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
end
Hash[calculated_data.map do |row|
- key = group_columns.map { |aliaz, column|
+ key = group_columns.map { |aliaz, column_name|
+ column = calculated_data.column_types.fetch(aliaz) do
+ column_for(column_name)
+ end
type_cast_calculated_value(row[aliaz], column)
}
key = key.first if key.size == 1
@@ -2,6 +2,12 @@
require 'models/developer'
class TimestampTest < ActiveRecord::TestCase
+ def test_group_by_date
+ keys = Topic.group("date_trunc('month', created_at)").count.keys
+ assert_operator keys.length, :>, 0
+ keys.each { |k| assert_kind_of Time, k }
+ end
+
def test_load_infinity_and_beyond
unless current_adapter?(:PostgreSQLAdapter)
return skip("only tested on postgresql")

0 comments on commit 160af90

Please sign in to comment.