instance method subquery_for

Ruby on Rails 5.2.8.1

Since v4.0.13 Last seen in v5.2.8.1 Private

Available in: v4.0.13 v4.1.16 v4.2.9 v5.2.8.1

Signature

subquery_for(key, select)

MySQL is too stupid to create a temporary table for use subquery, so we have to give it some prompting in the form of a subsubquery. Ugh!

Parameters

key req
select req
Source
# File activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb, line 723
        def subquery_for(key, select)
          subselect = select.clone
          subselect.projections = [key]

          # Materialize subquery by adding distinct
          # to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
          subselect.distinct unless select.limit || select.offset || select.orders.any?

          key_name = quote_column_name(key.name)
          Arel::SelectManager.new(subselect.as("__active_record_temp")).project(Arel.sql(key_name))
        end

Defined in activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb line 723 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

Type at least 2 characters to search.

↑↓ navigate · open · esc close