Skip to content

Commit 2ab3751

Browse files
committed
Remove duplicated attribute alias resolution in _select!
This is also resolved in `arel_column`.
1 parent 483d0dc commit 2ab3751

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ def select(*fields)
252252
def _select!(*fields) # :nodoc:
253253
fields.reject!(&:blank?)
254254
fields.flatten!
255-
fields.map! do |field|
256-
klass.attribute_alias?(field) ? klass.attribute_alias(field).to_sym : field
257-
end
258255
self.select_values += fields
259256
self
260257
end
@@ -1164,9 +1161,9 @@ def arel_columns(columns)
11641161
case field
11651162
when Symbol
11661163
field = field.to_s
1167-
arel_column(field) { connection.quote_table_name(field) }
1164+
arel_column(field, &connection.method(:quote_table_name))
11681165
when String
1169-
arel_column(field) { field }
1166+
arel_column(field, &:itself)
11701167
when Proc
11711168
field.call
11721169
else
@@ -1182,7 +1179,7 @@ def arel_column(field)
11821179
if klass.columns_hash.key?(field) && (!from || table_name_matches?(from))
11831180
arel_attribute(field)
11841181
else
1185-
yield
1182+
yield field
11861183
end
11871184
end
11881185

activerecord/test/cases/relation_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def test_selecting_aliased_attribute_quotes_column_name_when_from_is_used
292292
klass.create!(description: "foo")
293293

294294
assert_equal ["foo"], klass.select(:description).from(klass.all).map(&:desc)
295+
assert_equal ["foo"], klass.reselect(:description).from(klass.all).map(&:desc)
295296
end
296297

297298
def test_relation_merging_with_merged_joins_as_strings

0 commit comments

Comments
 (0)