File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
lib/active_record/relation Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,7 @@ def exists?(conditions = :none)
365
365
end
366
366
367
367
return false if !conditions || limit_value == 0
368
+ return !records . empty? if conditions == :none && loaded?
368
369
369
370
if eager_loading?
370
371
relation = apply_join_dependency ( eager_loading : false )
Original file line number Diff line number Diff line change @@ -285,6 +285,19 @@ def test_exists_returns_true_with_one_record_and_no_args
285
285
assert_equal true , Topic . exists?
286
286
end
287
287
288
+ def test_exists_with_loaded_relation
289
+ topics = Topic . all . load
290
+ assert_no_queries do
291
+ assert_equal true , topics . exists?
292
+ end
293
+
294
+ Topic . delete_all
295
+ topics = Topic . all . load
296
+ assert_no_queries do
297
+ assert_equal false , topics . exists?
298
+ end
299
+ end
300
+
288
301
def test_exists_returns_false_with_false_arg
289
302
assert_equal false , Topic . exists? ( false )
290
303
end
You can’t perform that action at this time.
0 commit comments