diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-22 06:14:33 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-22 06:14:33 +0900 |
commit | 6e599ee099ce9beeddfc938574225b943c144bd8 (patch) | |
tree | 19d27265eca4f934a08f619917a15329897d1ca3 /activerecord/lib | |
parent | 3b6602aa7a01fb415fce07ef32458b131e5762e1 (diff) | |
download | rails-6e599ee099ce9beeddfc938574225b943c144bd8.tar.gz rails-6e599ee099ce9beeddfc938574225b943c144bd8.tar.bz2 rails-6e599ee099ce9beeddfc938574225b943c144bd8.zip |
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.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 4 |
1 files changed, 3 insertions, 1 deletions
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 |