ruby-on-rails - 当 STI 与连接查询一起使用时,sql 中使用了错误的类类型
问题描述
我最近从 Rails 4.1.4 升级到 4.2.8,我的行为很奇怪。所以我们有
从它继承的表class Identity < ActiveRecord::Base
和表。Doctor, Assistant, Substitute
因此,当我不在这些课程之外并打电话时(rails 控制台,规格)
Doctor.all.to_sql
=>
"SELECT \"identities\".* FROM \"identities\" WHERE \"identities\".\"type\" IN ('Doctor')"
这很好。
当我从助理模型中的类方法进行相同的调用时,它会产生以下
Doctor.all.to_sql
=>
"SELECT \"identities\".* FROM \"identities\" WHERE \"identities\".\"type\" IN ('Assistant', 'Substitute')"
这是错误的。
当我在助手模型中的类方法中并做
Doctor.unscoped.all
=>"SELECT \"identities\".* FROM \"identities\" WHERE \"identities\".\"type\" IN ('Doctor')"
很好的查询。
我检查了我们是否在某处设置了 default_scope,但我们没有。此外,这非常棘手,因为当我这样做时,
SomeTable.joins(:identities)
我无法取消范围identities
,这会导致我查询错误。
所以,我不太确定升级后发生了什么,但我知道它确实适用于旧的 Rails 4.1.4。
任何提示都会有所帮助。
Regads
解决方案
升级到 Rails 4.2.11 后,问题消失了。我将付出更多努力在旧版本上重现这种行为,并在必要时向 Rails 团队报告。
推荐阅读
- python - kivy中的屏幕切换
- xml - 使用 shell 脚本从 xml 文件中提取最新版本
- c - 为什么在使用 ICC 双端编译器编译时,变量和函数会以“__be_”为前缀?
- eclipse - Tomcat 8 未出现在 Eclipse 服务器列表中
- r - 使用 for() 和 if() 计算值
- html - 如何阻止 Javascript/HTML 编辑 iFrame 的 src(在链接前添加我的服务器地址)属性?
- scala - 静态数据帧上的 mapGroupsWithState 函数,为什么?
- python - How to put certain instances of a text file to a list in python
- python - python 十六进制值作为输入整数
- android - Android launch_background 适合图像的宽度