diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-21 11:31:57 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-22 09:00:15 -0600 |
commit | c083ce6dd283303aaf0224943dcc759e52536adc (patch) | |
tree | fafb2643e268bc13bf4f5ab1964a0dcb5dbcd062 /activerecord/lib/active_record/relation/calculations.rb | |
parent | 281c92a346fe3575c417003b63d66f7f3a0a259c (diff) | |
download | rails-c083ce6dd283303aaf0224943dcc759e52536adc.tar.gz rails-c083ce6dd283303aaf0224943dcc759e52536adc.tar.bz2 rails-c083ce6dd283303aaf0224943dcc759e52536adc.zip |
Encapsulate knowledge of type objects on `ActiveRecord::Result`
Attempting to reduce the number of places that care about the details of
how type casting occurs. We remove the type casting of the primary key
in `JoinDependecy`, rather than encapsulating it. It was originally
added for consistency with
https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211,
but that conditional was later removed in
https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734.
What is important is that the same row twice will have the same value
for the primary key, which it will.
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index c80ffbae92..b4ae204813 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -178,16 +178,7 @@ module ActiveRecord columns_hash.key?(cn) ? arel_table[cn] : cn } result = klass.connection.select_all(relation.arel, nil, bind_values) - columns = result.columns.map do |key| - klass.column_types.fetch(key) { - result.column_types.fetch(key) { result.identity_type } - } - end - - result = result.rows.map do |values| - columns.zip(values).map { |column, value| column.type_cast_from_database value } - end - columns.one? ? result.map!(&:first) : result + result.cast_values(klass.column_types) end end |