ruby-on-rails - 测试 ActiveRecord 时如何解释不明确的列名?
问题描述
我正在协助 gem activerecord-sqlserver-adapter完成它对 Rails 5.2.3 的测试。我试图了解下面(和这里)的 ActiveRecord 测试。
# 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')
任何人都可以让我了解文档中原始形式的上述行在这种情况下应该如何在不传递特定表名的情况下工作?
解决方案
推荐阅读
- mongodb - 为什么在文档上使用范围运算符时不涵盖查询?
- chef-infra - 如何找出节点在厨师服务器上注册的日期?
- c# - Kerberos 模拟级别“模拟”而不是“委托”
- c# - Azure 云服务(经典)检索客户端 IP 地址
- javascript - Import Unexpected identifier + SyntaxError: Unexpected string
- css - 在 fabrik (joomla) 中显示图像?
- react-native - 反应本机标头问题
- web - 如何将整个 _site 文件夹从我的 Jekyll 博客站点复制到我在 Linux 中托管的主网站的博客文件夹
- c# - 如何正确裁剪图像的一部分?
- c# - 如何使用.Net将转换为字节的图像传递给detectdocumenttextresult和detectdocumenttextresponse中的请求?