“这不是真的”使用 Rails 3 查询或 meta_where
我需要的可能非常简单:
Table.where('field is not true')
但我无法弄清楚这是如何使用 Rails 3 查询接口完成的,并且可能使用 meta_where。问题是,虽然“:field.not_eq => nil”正确地翻译为“IS NOT NULL”,但“:field.not_eq => true”变成了“!= 1”,这显然与“IS NOT TRUE”(mysql 和 postgresql 扩展)。
What I need is probably very simple:
Table.where('field is not true')
but I can't figure how this is done with Rails 3 query interface, and probably with meta_where. The problem is that while ":field.not_eq => nil" translates properly to "IS NOT NULL", ":field.not_eq => true" becomes "!= 1", which is clearly not the same as "IS NOT TRUE" (mysql and postgresql extension).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mysql中没有布尔值,请参阅: http:// /dev.mysql.com/doc/refman/5.1/en/numeric-type-overview.html
正如您所看到的,布尔值始终是转换为 1 或 0 的tinyints,这就是为什么 Rails 将创建“field != 1”而不是 field is not true。
不确定postgresql通过。
There are no booleans in mysql, see: http://dev.mysql.com/doc/refman/5.1/en/numeric-type-overview.html
As you see booleans are always tinyints which translate into 1 or 0, this is why rails will create "field != 1" instead of field is not true.
Not sure about postgresql through.
这将是创建 github 分支的绝佳机会:) 这完全是一个应该添加到 meta_where 的功能。
This would be a great opportunity to make a github branch :) It's totally a feature that should be added to meta_where.