Rails3 和 Arel 使用 IN 和子选择进行选择
我有一个名为翻译的表。 (以及相应的 ActiveRecord 类)。 该表包含以下字段 id、键和值
我想选择键与给定查询匹配的所有翻译+与查询不匹配的所有翻译,但与与查询匹配的翻译共享键。
生成的 SQL 可能看起来像这样:
SELECT * FROM TRANSLATIONS where key in
(select key from Translations where value like '%some search%')
我已经尝试了一些方法,但我似乎无法弄清楚。 关于如何在 Arel 中表达这一点有什么想法吗?
I have a table called translations. (And a correspoding ActiveRecord class).
This table contains the following fields
id, key and value
I would like to select all translations where the key matches a given query + all the translations that don't match the query, but share the key with a translation which does matches the query.
The resulting SQL could look something like this:
SELECT * FROM TRANSLATIONS where key in
(select key from Translations where value like '%some search%')
I've tried a few things, but I can't seem to figure it out.
Any ideas on how to express this in Arel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西应该有效:
Something like this should work:
与 @valodzka 类似,但在 :key 符号周围添加“t[....]”
Similar to @valodzka, but add "t[....]" around the :key symbol