File tree Expand file tree Collapse file tree 3 files changed +3
-15
lines changed
lib/active_record/relation Expand file tree Collapse file tree 3 files changed +3
-15
lines changed Original file line number Diff line number Diff line change 78
78
79
79
* Nony Dutton *
80
80
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
-
87
81
* Add a ` filter` option to ` in_order_of` to prioritize certain values in the sorting without filtering the results
88
82
by these values.
89
83
Original file line number Diff line number Diff line change @@ -366,12 +366,6 @@ def exists?(conditions = :none)
366
366
367
367
return false if !conditions || limit_value == 0
368
368
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
-
375
369
if eager_loading?
376
370
relation = apply_join_dependency ( eager_loading : false )
377
371
return relation . exists? ( conditions )
Original file line number Diff line number Diff line change @@ -291,15 +291,15 @@ def test_exists_returns_false_with_false_arg
291
291
292
292
def test_exists_with_loaded_relation
293
293
topics = Topic . all . load
294
- assert_no_queries do
294
+ assert_queries_match ( /SELECT 1 AS one/i , count : 1 ) do
295
295
assert_predicate topics , :exists?
296
296
end
297
297
end
298
298
299
299
def test_exists_with_empty_loaded_relation
300
300
Topic . delete_all
301
301
topics = Topic . all . load
302
- assert_no_queries do
302
+ assert_queries_match ( /SELECT 1 AS one/i , count : 1 ) do
303
303
assert_not_predicate topics , :exists?
304
304
end
305
305
end
@@ -310,7 +310,7 @@ def test_exists_with_loaded_relation_having_unsaved_records
310
310
assert_not_empty posts
311
311
posts . each ( &:destroy )
312
312
313
- assert_no_queries do
313
+ assert_queries_match ( /SELECT 1 AS one/i ) do
314
314
assert_not_predicate posts , :exists?
315
315
end
316
316
end
You can’t perform that action at this time.
0 commit comments