Consulta sobre el Campo Hash Mongoid
Quiero consultar un campo Hash para una clase Mongoid. No estoy seguro de cómo puedo hacer esto con las condiciones?
Aquí hay un ejemplo:
class Person
include Mongoid::Document
field :things, :type => Hash
end
Entonces, digamos que tengo esto:
p = Person.new
p.things = {}
p.things[:tv] = "Samsung"
Quiero preguntar por la primera persona con un televisor que es un Samsung...
People.first(:conditions => ?????
Gracias de antemano.
24
1 answers
Person.where('things.tv' => 'Samsung').first
Aquí es donde Mongoid y MongoDB realmente brillan. Métodos de Criterios de Mongoid (Person.where
, Person.any_of
, Person.excludes
, etc.) le dará mucha más flexibilidad que los buscadores de estilo ActiveRecord (pasando un hash :conditions
a Person.find
, Person.first
, etc.)
El sitio de Mongoid tiene una gran documentación sobre cómo usar Criteria
:
43
Author: bowsersenior,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-12 09:09:10
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-12 09:09:10