aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 435cef901b..b83032e2a0 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -280,8 +280,8 @@ module ActiveRecord
return false if !conditions
- relation = apply_join_dependency(self, construct_join_dependency)
- return false if ActiveRecord::NullRelation === relation
+ relation = apply_join_dependency(self, construct_join_dependency_for_exists)
+ return false if ActiveRecord::NullRelation === relation || limit_value == 0
relation = relation.except(:select, :order).select(ONE_AS_ONE).limit(1)
@@ -359,6 +359,11 @@ module ActiveRecord
ActiveRecord::Associations::JoinDependency.new(@klass, including, joins)
end
+ def construct_join_dependency_for_exists
+ including = (eager_load_values + includes_values) & references_values.map(&:to_sym)
+ ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
+ end
+
def construct_relation_for_association_calculations
from = arel.froms.first
if Arel::Table === from