aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-29 14:26:38 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-29 14:27:33 +0000
commitc99d507fccca2e9e4d12e49b4387e007c5481ae9 (patch)
tree269b10745091c0c0e3941ab756cec0130cbc11bd /activerecord/lib
parent0b8b68209ded58e40cc18f3fef2f2c38e3730bb8 (diff)
downloadrails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.tar.gz
rails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.tar.bz2
rails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.zip
Deprecate implicit eager loading. Closes #950.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb2
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb2
-rw-r--r--activerecord/lib/active_record/associations/preloader/association.rb1
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb1
-rw-r--r--activerecord/lib/active_record/relation.rb14
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb4
6 files changed, 19 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 6f8b76abda..090f690f0d 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -20,7 +20,7 @@ module ActiveRecord
# It's okay to just apply all these like this. The options will only be present if the
# association supports that option; this is enforced by the association builder.
scope = scope.apply_finder_options(options.slice(
- :readonly, :include, :order, :limit, :joins, :group, :having, :offset, :select))
+ :readonly, :include, :eager_load, :order, :limit, :joins, :group, :having, :offset, :select))
if options[:through] && !options[:include]
scope = scope.includes(source_options[:include])
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index d4f59100e8..776f0d0469 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -1,7 +1,7 @@
module ActiveRecord::Associations::Builder
class Association #:nodoc:
class_attribute :valid_options
- self.valid_options = [:class_name, :foreign_key, :select, :conditions, :include, :extend, :readonly, :validate]
+ self.valid_options = [:class_name, :foreign_key, :select, :conditions, :include, :eager_load, :extend, :readonly, :validate]
# Set by subclasses
class_attribute :macro
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb
index 779f8164cc..298decb0f1 100644
--- a/activerecord/lib/active_record/associations/preloader/association.rb
+++ b/activerecord/lib/active_record/associations/preloader/association.rb
@@ -100,6 +100,7 @@ module ActiveRecord
scope = scope.select(preload_options[:select] || options[:select] || table[Arel.star])
scope = scope.includes(preload_options[:include] || options[:include])
+ scope = scope.eager_load(preload_options[:eager_load] || options[:eager_load])
if options[:as]
scope = scope.where(
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index ad6374d09a..97898c53ae 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -53,6 +53,7 @@ module ActiveRecord
else
if options[:conditions]
through_options[:include] = options[:include] || options[:source]
+ through_options[:eager_load] = options[:eager_load] || options[:source]
through_options[:conditions] = options[:conditions]
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 258c1959a0..bbadca84be 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
require 'active_support/core_ext/object/blank'
+require 'active_support/deprecation'
module ActiveRecord
# = Active Record Relation
@@ -521,7 +522,18 @@ module ActiveRecord
# 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
- (tables_in_string(to_sql) - joined_tables).any?
+ referenced_tables = (tables_in_string(to_sql) - joined_tables)
+ if referenced_tables.any?
+ ActiveSupport::Deprecation.warn(
+ "Your query appears to reference tables (#{referenced_tables.join(', ')}) that are not " \
+ "explicitly joined. This implicit joining is deprecated, so you must explicitly " \
+ "reference the tables. For example, instead of Author.includes(:posts).where(\"posts.name = 'foo'\"), " \
+ "you should write Author.eager_load(:posts).where(\"posts.name = 'foo'\")."
+ )
+ true
+ else
+ false
+ end
end
def tables_in_string(string)
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index ba882beca9..a5194beae5 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -113,7 +113,7 @@ module ActiveRecord
result
end
- VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend,
+ VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend, :eager_load,
:order, :select, :readonly, :group, :having, :from, :lock ]
def apply_finder_options(options)
@@ -124,7 +124,7 @@ module ActiveRecord
finders = options.dup
finders.delete_if { |key, value| value.nil? && key != :limit }
- ([:joins, :select, :group, :order, :having, :limit, :offset, :from, :lock, :readonly] & finders.keys).each do |finder|
+ ([:joins, :select, :group, :order, :having, :limit, :offset, :from, :lock, :readonly, :eager_load] & finders.keys).each do |finder|
relation = relation.send(finder, finders[finder])
end