2010-11-22 20 views
0
bir örneği nesneden

i aşağıdaki nesne var ki:çağrılması bulmak (: hepsi) Mongoid

{ "text" : "oa3", "topic_ids" : [ ObjectId("4cea00efd8030a35eb000004") ]} 

bu sözde "bir"

a.topics.find(:all).count #this returns 0 

hissediyorum temsil eden bir nesne olduğunu ben Bunu yanlış yapıyorum.

Yineleyici bu belirli nesnedeki konular için nasıl alabilirim?

cevap

4
# get the number of topics 
a.topics.count 

# same but faster 
a.topic_ids.count 

# get an array of the topics 
a.topics.entries 

# do a query on the topics 
a.topics.where(:title => 'Movies').entries 

anahtar sorguları yerine ActiveRecord tarzı bulucuları (Model.find) yapmak Mongoid en Kriterleri (Model.where veya Model.association.where) kullanmaktır. ActiveRecord tarzı bulucular gerçekten kolaylık sağlamak içindir - Mongoid'in gerçek gücü Kriterlerindedir. Mongoid sitesinde

diğer bilgiler:

http://mongoid.org/docs/querying/