【发布时间】:2011-07-23 17:53:54
【问题描述】:
返回所有嵌入文档的最有效方法是什么?
假设用户嵌入了许多地址...在 ActiveRecord 中,我可以使用 Address.count 计算它们的数量。这样做的嵌入式文档/mongo 版本是什么?
当它有 2 层或更多层时怎么样? Product > Pressing > Variations... 我怎样才能计算所有书籍、所有作者的所有章节?与用 Ruby 做这一切相比如何?
Product has_many Pressings
Pressing has_many Variations
Product
def self.pressings
all.collect { |p| p.pressings }.flatten
end
def self.variations
self.pressings.collect { |p| p.variations }.flatten
end
end
【问题讨论】: