测试ActiveRecord时如何解释模棱两可的列名?

我正在努力协助宝石activerecord-sqlserver-adapter完成对Rails 5.2.3的测试。我试图了解下面的activeRecord测试(和here)。

# File activerecord/test/cases/relations_test.rb
def test_pluck_with_from_includes_quoted_original_table_name
  relation = Comment.joins(:post).order(:id)
  subquery = Comment.from("#{Comment.quoted_table_name} /*! USE INDEX (PRIMARY) */").joins(:post).order(:id)
  assert_equal relation.pluck(:id),subquery.pluck(:id)
end

当前运行测试时,出现以下错误。

Error:
RelationTest#test_pluck_with_from_includes_quoted_original_table_name_coerced:
activeRecord::StatementInvalid: TinyTds::Error: Ambiguous column name 'id'.: SELECT [id] FROM [comments] /*! USE INDEX (PRIMARY) */ LEFT OUTER JOIN [posts] ON [posts].[id] = [comments].[post_id]  ORDER BY [id] ASC

bin/rails test mnt/c/Users/mcdonaldd/Documents/open_source/sqlserver-main/test/cases/coerced_tests.rb:763

据我所知,这是我期望的,因为我没有指定“ id”列应来自哪个表...但是,我猜测构建通过测试的解决方案不是将其更改为。

assert_equal relation.pluck(:id),subquery.pluck('posts.id')

任何人都可以让我了解文档中原始格式的上一行在这种情况下如何在不传递特定表名的情况下工作吗?

yoyo520621 回答:测试ActiveRecord时如何解释模棱两可的列名?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3109132.html

大家都在问