Skip to content

Commit

Permalink
Merge pull request #34329 from r7kamura/feature/where-exclamation-con…
Browse files Browse the repository at this point in the history
…sistency

Ignore empty condition on #construct_relation_for_exists
  • Loading branch information
kamipo committed Oct 27, 2018
1 parent a1ed097 commit de9768d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def construct_relation_for_exists(relation, conditions)

case conditions
when Array, Hash
relation.where!(conditions)
relation.where!(conditions) unless conditions.empty?
else
relation.where!(primary_key => conditions) unless conditions == :none
end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def test_exists_with_nil_arg
assert_equal true, Topic.first.replies.exists?
end

def test_exists_with_empty_hash_arg
assert_equal true, Topic.exists?({})
end

# Ensure +exists?+ runs without an error by excluding distinct value.
# See https://github.com/rails/rails/pull/26981.
def test_exists_with_order_and_distinct
Expand Down

0 comments on commit de9768d

Please sign in to comment.