Skip to content

Commit eb32f1e

Browse files
authored
Merge pull request rails#50356 from Shopify/fix-async-none-pluck
Fix `Model.none.async_pluck` to return a Promise
2 parents 5a1b2b8 + f8e842f commit eb32f1e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,13 @@ def calculate(operation, column_name)
260260
#
261261
# See also #ids.
262262
def pluck(*column_names)
263-
return [] if @none
263+
if @none
264+
if @async
265+
return Promise::Complete.new([])
266+
else
267+
return []
268+
end
269+
end
264270

265271
if loaded? && all_attributes?(column_names)
266272
result = records.pluck(*column_names)

activerecord/test/cases/calculations_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,15 @@ def test_pluck
823823
assert_async_equal [1, 2, 3, 4, 5], Topic.order(:id).async_pluck(:id)
824824
end
825825

826-
def test_pluck_async_on_loaded_relation
826+
def test_async_pluck_on_loaded_relation
827827
relation = Topic.order(:id).load
828828
assert_async_equal relation.pluck(:id), relation.async_pluck(:id)
829829
end
830830

831+
def test_async_pluck_none_relation
832+
assert_async_equal [], Topic.none.async_pluck(:id)
833+
end
834+
831835
def test_pluck_with_empty_in
832836
assert_queries(0) do
833837
assert_equal [], Topic.where(id: []).pluck(:id)

0 commit comments

Comments
 (0)