diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 6fa99c6d94761..c779734f0704b 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -444,11 +444,11 @@ def construct_relation_for_exists(conditions) relation = except(:select, :distinct, :order)._select!(ONE_AS_ONE).limit!(1) end - case conditions - when Array, Hash + if conditions.is_a?(Array) && conditions.first.is_a?(String) || conditions.is_a?(Hash) relation.where!(conditions) unless conditions.empty? else - relation.where!(primary_key => conditions) unless conditions == :none + conditions = [conditions] if klass.composite_primary_key? + relation.where!(primary_key => conditions) unless conditions == :none || conditions.empty? end relation