aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-19 14:50:10 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-19 14:50:10 +0000
commit2a2afca0955fa43a0796d727399f30a2c09bfc5d (patch)
treecbf50437047a0ae857a9a88681d7470bd5b0f90f /activerecord/lib
parent5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e (diff)
downloadrails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.tar.gz
rails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.tar.bz2
rails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.zip
Ensure that Associations#include_eager_conditions? checks both scoped and explicit conditions [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4232 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 88a2ad43ba..c0fdca3da9 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1192,16 +1192,24 @@ module ActiveRecord
add_limit!(sql, options, scope)
return sanitize_sql(sql)
end
-
+
+ # Checks if the conditions reference a table other than the current model table
def include_eager_conditions?(options)
- conditions = scope(:find, :conditions) || options[:conditions]
- return false unless conditions
- conditions = conditions.first if conditions.is_a?(Array)
- conditions.scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name|
+ # look in both sets of conditions
+ conditions = [scope(:find, :conditions), options[:conditions]].inject([]) do |all, cond|
+ case cond
+ when nil then all
+ when Array then all << cond.first
+ else all << cond
+ end
+ end
+ return false unless conditions.any?
+ conditions.join(' ').scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name|
condition_table_name != table_name
end
end
+ # Checks if the query order references a table other than the current model's table.
def include_eager_order?(options)
order = options[:order]
return false unless order