Skip to content

Commit 0077a16

Browse files
[FIX] Pluck columns should correctly casts types when using postgresql
1 parent 3769f1e commit 0077a16

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def type_cast_pluck_values(result, columns)
604604
model.attribute_types.fetch(name = result.columns[i]) do
605605
join_dependencies ||= build_join_dependencies
606606
lookup_cast_type_from_join_dependencies(name, join_dependencies) ||
607-
result.column_types[name] || Type.default_value
607+
result.column_types[i] || Type.default_value
608608
end
609609
end
610610
end

activerecord/test/cases/calculations_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@ def test_pluck_type_cast
847847
assert_equal [ topic.approved ], relation.pluck(:approved)
848848
assert_equal [ topic.last_read ], relation.pluck(:last_read)
849849
assert_equal [ topic.written_on ], relation.pluck(:written_on)
850+
assert_equal(
851+
[[Topic.minimum(:written_on), Topic.minimum(:replies_count)]],
852+
relation.pluck("min(written_on)", "min(replies_count)")
853+
)
850854
end
851855

852856
def test_pluck_type_cast_with_conflict_column_names

0 commit comments

Comments
 (0)