Flowdock
references_eager_loaded_tables?() private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/relation.rb, line 604
    def references_eager_loaded_tables?
      joined_tables = arel.join_sources.map do |join|
        if join.is_a?(Arel::Nodes::StringJoin)
          tables_in_string(join.left)
        else
          [join.left.table_name, join.left.table_alias]
        end
      end

      joined_tables += [table.name, table.table_alias]

      # always convert table names to downcase as in Oracle quoted table names are in uppercase
      joined_tables = joined_tables.flatten.compact.map { |t| t.downcase }.uniq
      string_tables = tables_in_string(to_sql)

      if (references_values - joined_tables).any?
        true
      elsif !ActiveRecord::Base.disable_implicit_join_references &&
            (string_tables - joined_tables).any?
        ActiveSupport::Deprecation.warn(
          "It looks like you are eager loading table(s) (one of: #{string_tables.join(', ')}) "            "that are referenced in a string SQL snippet. For example: \n"            "\n"            "    Post.includes(:comments).where(\"comments.title = 'foo'\")\n"            "\n"            "Currently, Active Record recognizes the table in the string, and knows to JOIN the "            "comments table to the query, rather than loading comments in a separate query. "            "However, doing this without writing a full-blown SQL parser is inherently flawed. "            "Since we don't want to write an SQL parser, we are removing this functionality. "            "From now on, you must explicitly tell Active Record when you are referencing a table "            "from a string:\n"            "\n"            "    Post.includes(:comments).where(\"comments.title = 'foo'\").references(:comments)\n"            "\n"            "If you don't rely on implicit join references you can disable the feature entirely "            "by setting `config.active_record.disable_implicit_join_references = true`."
        )
        true
      else
        false
      end
    end
Register or log in to add new notes.