aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-13 02:06:06 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-13 02:47:46 +0900
commit0ee96d13de29680e148ccb8e5b68025f29fd091c (patch)
treee8e2095bc74f34b8a0447cace738368e8ff79bef /activerecord/lib/active_record/relation/calculations.rb
parented9acb4fcc793ce1ab68a0e5076dc9458cc7f218 (diff)
downloadrails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.gz
rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.bz2
rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.zip
Fix `pluck` and `select` with custom attributes
Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index cef31bea94..bdd3c540bb 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -186,11 +186,9 @@ module ActiveRecord
relation = apply_join_dependency
relation.pluck(*column_names)
else
- disallow_raw_sql!(column_names)
+ klass.disallow_raw_sql!(column_names)
relation = spawn
- relation.select_values = column_names.map { |cn|
- @klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn
- }
+ relation.select_values = column_names
result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil) }
result.cast_values(klass.attribute_types)
end