提交 de354cc3 编写于 作者: R Ryuta Kamizono

Using table name qualified column names unless having SELECT list explicitly

Previously table name qualified `*` is used in that case. If it is not
qualified with a table name, an ambiguous column name error will occur
when using JOINs.
上级 475a0f88
......@@ -1040,8 +1040,8 @@ def convert_join_strings_to_ast(table, joins)
def build_select(arel)
if select_values.any?
arel.project(*arel_columns(select_values.uniq))
elsif @klass.ignored_columns.any?
arel.project(*arel_columns(@klass.column_names.map(&:to_sym)))
elsif klass.ignored_columns.any?
arel.project(*klass.column_names.map { |field| arel_attribute(field) })
else
arel.project(table[Arel.star])
end
......
......@@ -1498,10 +1498,14 @@ def test_default_values_are_deeply_dupped
test "column names are quoted when using #from clause and model has ignored columns" do
refute_empty Developer.ignored_columns
query = Developer.from("`developers`").to_sql
quoted_id = Developer.connection.quote_table_name("id")
query = Developer.from("developers").to_sql
quoted_id = "#{Developer.quoted_table_name}.#{Developer.quoted_primary_key}"
assert_match(/SELECT #{quoted_id}.* FROM `developers`/, query)
assert_match(/SELECT #{quoted_id}.* FROM developers/, query)
end
test "using table name qualified column names unless having SELECT list explicitly" do
assert_equal developers(:david), Developer.from("developers").joins(:shared_computers).take
end
test "protected environments by default is an array with production" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册