0
我使用Mongoid构建Rails 4应用程序。通过关系过滤Mongoid集合
我现在的问题是如何通过他们自己的关系来过滤一些Mongoid对象,并在结尾处有一个Mongoid :: Criteria而不是一个Array。
这是一些示例代码:
class Editor
include Mongoid::Document
has_many :books
def likes
books.collect { |book| book.likes }
end
end
class Book
include Mongoid::Document
belongs_to :editor
end
我希望能够做的是一样的东西:
Editor.last.likes.where(:created_at.gt => 10.days.ago)
但当然,这并不为Editor.last工作。喜欢返回一个数组,而不是一个Mongoid ::条件
我知道Mongoid有一个聚合框架,但它不是完全清楚如何使用它,也不是如果它是解决我的问题的最佳方法。
对此提出建议?
TIA, NGW