diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-14 09:19:39 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-14 09:34:05 +0900 |
commit | eacc97ce3ca4108acc5f1bf6bf5e479a52a5b012 (patch) | |
tree | 4516402e17e9a2d30c665a751608399bb5af18f6 /activerecord | |
parent | 5a4cd4fc6fbf1d3036172be5809d467a0395c567 (diff) | |
download | rails-eacc97ce3ca4108acc5f1bf6bf5e479a52a5b012.tar.gz rails-eacc97ce3ca4108acc5f1bf6bf5e479a52a5b012.tar.bz2 rails-eacc97ce3ca4108acc5f1bf6bf5e479a52a5b012.zip |
Don't use `quoted_table_name` in `limited_ids_for`
Because `quoted_table_name` doesn't respect table alias. We should use
`arel_attribute` for that, so I added `column_name_from_arel_node` to
generate column name from an arel node.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 47881e3305..8c889f98f5 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -442,7 +442,11 @@ module ActiveRecord end def column_name_for_operation(operation, node) # :nodoc: - visitor.accept(node, collector).value + column_name_from_arel_node(node) + end + + def column_name_from_arel_node(node) # :nodoc: + visitor.accept(node, Arel::Collectors::SQLString.new).value end def default_index_type?(index) # :nodoc: diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 2aed941916..c92d5a52f4 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -413,7 +413,9 @@ module ActiveRecord def limited_ids_for(relation) values = @klass.connection.columns_for_distinct( - "#{quoted_table_name}.#{quoted_primary_key}", relation.order_values) + connection.column_name_from_arel_node(arel_attribute(primary_key)), + relation.order_values + ) relation = relation.except(:select).select(values).distinct! |