Skip to content

Commit

Permalink
fix time typcasting on group counts in PG
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 29, 2012
1 parent 8faf2b3 commit 160af90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/relation/calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/adapters/postgresql/timestamp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 160af90

Please sign in to comment.