ruby on rails - MongoDB : Search on multiple keys on embeds documents -


i've 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 able find translation documents including particular locale in given state.

translation.where('locales.code' => 'en', 'locales.state' => false).all 

the problem query translation documents embedding locale code=en , locale state=false not on same sub document.

any appreciated, thank you!

try this:

translation.where(:locales.matches => {:code=> 'en', :state=> false}).all 

example here


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -