Merge pull request #18744 from mfazekas/no-table-name-with-from

Fix appending table_name to select and group when used with subquery (fr...
上级 2bc72ae2
......@@ -999,11 +999,15 @@ def build_select(arel)
end
def arel_columns(columns)
columns.map do |field|
if (Symbol === field || String === field) && columns_hash.key?(field.to_s)
arel_table[field]
else
field
if from_value
columns
else
columns.map do |field|
if (Symbol === field || String === field) && columns_hash.key?(field.to_s)
arel_table[field]
else
field
end
end
end
end
......
......@@ -157,6 +157,17 @@ def test_finding_with_subquery_without_select_does_not_change_the_select
end
end
def test_select_with_subquery_in_from_does_not_use_original_table_name
relation = Comment.group(:type).select('COUNT(post_id) AS post_count, type')
subquery = Comment.from(relation).select('type','post_count')
assert_equal(relation.map(&:post_count).sort,subquery.map(&:post_count).sort)
end
def test_group_with_subquery_in_from_does_not_use_original_table_name
relation = Comment.group(:type).select('COUNT(post_id) AS post_count,type')
subquery = Comment.from(relation).group('type').average("post_count")
assert_equal(relation.map(&:post_count).sort,subquery.values.sort)
end
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册