aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-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