From 6e599ee099ce9beeddfc938574225b943c144bd8 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 22 Feb 2019 06:14:33 +0900 Subject: Fix `pluck` and `select` with `from` if `from` has original table name This is caused by 0ee96d1. Since #18744, `select` columns doesn't be qualified by table name if using `from`. 0ee96d1 follows that for `pluck` as well. But people depends that `pluck` columns are qualified even if using `from`. So I've fixed that to be qualified if `from` has the original table name to keep the behavior as much as before. Fixes #35359. --- activerecord/lib/active_record/relation/query_methods.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 5563dfb6c9..f69b85af66 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1068,8 +1068,10 @@ module ActiveRecord def arel_column(field) field = klass.attribute_alias(field) if klass.attribute_alias?(field) + from = from_clause.name || from_clause.value - if klass.columns_hash.key?(field) && !from_clause.value + if klass.columns_hash.key?(field) && + (!from || from == table.name || from == connection.quote_table_name(table.name)) arel_attribute(field) else yield -- cgit v1.2.3