Skip to content

Commit

Permalink
Add composite key support to Model.exists?
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeDupuis committed Mar 12, 2024
1 parent 4d3e291 commit 760c6f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 760c6f5

Please sign in to comment.