Using Mongoid / MongoDB, how can I find a document whose name in either available language match my where query ?
Assume I have a model with a localized field and many translations
class Foo
field :name, localize: true
end
Foo.create(name_translations: {
'fr' => 'Ingénierie logicielle',
'en' => 'Computer Software'
})
The .find_by(name: )
method only seems to find the I18n.current
language (French in my case), how can I search across all translations ?
I'm trying several of variations of Foo.find_by(name_translations: 'Computer Software)
, but I'm still getting empty results...
Maybe there's a more elegant solution, but since it appears that
name
is an embedded document, you'll need to match against each language: