From 34402c762384336badbce0e2d20dbbe580c88cbe Mon Sep 17 00:00:00 2001
From: Yves Senn <yves.senn@gmail.com>
Date: Fri, 15 Mar 2013 14:44:48 +0100
Subject: make it possible to disable implicit join references.

Closes #9712.
---
 activerecord/lib/active_record/core.rb     | 8 ++++++++
 activerecord/lib/active_record/relation.rb | 8 ++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

(limited to 'activerecord/lib')

diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 72371be657..aa56219755 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -69,6 +69,14 @@ module ActiveRecord
       mattr_accessor :timestamped_migrations, instance_writer: false
       self.timestamped_migrations = true
 
+      ##
+      # :singleton-method:
+      # Disable implicit join references. This feature was deprecated with Rails 4.
+      # If you don't make use of implicit references but still see deprecation warnings
+      # you can disable the feature entirely. This will be the default with Rails 4.1.
+      mattr_accessor :disable_implicit_join_references, instance_writer: false
+      self.disable_implicit_join_references = false
+
       class_attribute :connection_handler, instance_writer: false
       self.connection_handler = ConnectionAdapters::ConnectionHandler.new
     end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 50723b4848..037097d2dd 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -595,7 +595,8 @@ module ActiveRecord
 
       if (references_values - joined_tables).any?
         true
-      elsif (string_tables - joined_tables).any?
+      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" \
@@ -609,7 +610,10 @@ module ActiveRecord
           "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"
+          "    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
-- 
cgit v1.2.3