I’ve a Translation document embeds many Translation Locales documents :
class Translation
include Mongoid::Document
field :key, :type => String
embeds_many :locales, :class_name => 'TranslationLocale'
end
class TranslationLocale
include Mongoid::Document
embedded_in :translation
field :code, :type => String
field :state, :type => Boolean, :default => false
field :text, :type => String
end
I want to be able to find all Translation documents including a particular locale in a given state.
Translation.where('locales.code' => 'en', 'locales.state' => false).all
The problem is that query will look for Translation documents embedding a locale with code=en and a locale with state=false but not necessarily on the same sub document.
Any help is appreciated, thank you!
Try this:
Example from here