From 2a2afca0955fa43a0796d727399f30a2c09bfc5d Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 19 Apr 2006 14:50:10 +0000 Subject: 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 --- activerecord/lib/active_record/associations.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3