【发布时间】:2018-04-24 16:54:43
【问题描述】:
使用 Mongoid / MongoDB,我怎样才能找到一个文档,它的任何一种可用语言的名称都与我的 where 查询匹配?
假设我有一个具有本地化字段和许多翻译的模型
class Foo
field :name, localize: true
end
Foo.create(name_translations: {
'fr' => 'Ingénierie logicielle',
'en' => 'Computer Software'
})
.find_by(name: ) 方法似乎只能找到 I18n.current 语言(在我的情况下是法语),我如何搜索所有翻译?
我正在尝试Foo.find_by(name_translations: 'Computer Software) 的几种变体,但我仍然得到空结果...
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 mongoid mongoid6