Skip to content

Commit 3b6af16

Browse files
committed
Revert "Merge pull request rails#51987 from fatkodima/exists-and-loaded2"
This reverts commit c9075e3, reversing changes made to a14eb2d.
1 parent def0397 commit 3b6af16

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

activerecord/CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@
7878

7979
*Nony Dutton*
8080

81-
* Optimize `Relation#exists?` when records are loaded and the relation has no conditions.
82-
83-
This can avoid queries in some cases.
84-
85-
*fatkodima*
86-
8781
* Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
8882
by these values.
8983

activerecord/lib/active_record/relation/finder_methods.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,6 @@ def exists?(conditions = :none)
366366

367367
return false if !conditions || limit_value == 0
368368

369-
# Ignore if we have records which have saved changes since the load, because the
370-
# relation can be a CollectionProxy and we updated the reference to the owner record.
371-
if conditions == :none && loaded? && records.none?(&:saved_changes?)
372-
return records.any?(&:persisted?)
373-
end
374-
375369
if eager_loading?
376370
relation = apply_join_dependency(eager_loading: false)
377371
return relation.exists?(conditions)

activerecord/test/cases/finder_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ def test_exists_returns_false_with_false_arg
291291

292292
def test_exists_with_loaded_relation
293293
topics = Topic.all.load
294-
assert_no_queries do
294+
assert_queries_match(/SELECT 1 AS one/i, count: 1) do
295295
assert_predicate topics, :exists?
296296
end
297297
end
298298

299299
def test_exists_with_empty_loaded_relation
300300
Topic.delete_all
301301
topics = Topic.all.load
302-
assert_no_queries do
302+
assert_queries_match(/SELECT 1 AS one/i, count: 1) do
303303
assert_not_predicate topics, :exists?
304304
end
305305
end
@@ -310,7 +310,7 @@ def test_exists_with_loaded_relation_having_unsaved_records
310310
assert_not_empty posts
311311
posts.each(&:destroy)
312312

313-
assert_no_queries do
313+
assert_queries_match(/SELECT 1 AS one/i) do
314314
assert_not_predicate posts, :exists?
315315
end
316316
end

0 commit comments

Comments
 (0)