Skip to content

Commit a64b536

Browse files
committed
Fix pluck with using join alias
Correctly adds references values when alias qualified column name is passed. Fixes rails#53063.
1 parent 15ddce9 commit a64b536

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,7 @@ def arel_column(field)
19561956
table[field]
19571957
elsif field.match?(/\A\w+\.\w+\z/)
19581958
table, column = field.split(".")
1959+
self.references_values |= [Arel.sql(table, retryable: true)]
19591960
predicate_builder.resolve_arel_attribute(table, column) do
19601961
lookup_table_klass_from_join_dependencies(table)
19611962
end

activerecord/test/cases/calculations_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@ def test_pluck_with_join
11411141
assert_equal [[2, 2], [4, 4]], Reply.includes(:topic).order(:id).pluck(:id, :"topics.id")
11421142
end
11431143

1144+
def test_pluck_with_join_alias
1145+
assert_equal [[2, 1], [4, 3]], Reply.includes(:topic).order(:id).pluck(:id, :"topic.id")
1146+
end
1147+
11441148
def test_group_by_with_order_by_virtual_count_attribute
11451149
expected = { "SpecialPost" => 1, "StiPost" => 2 }
11461150
actual = Post.group(:type).order(:count).limit(2).maximum(:comments_count)

0 commit comments

Comments
 (0)