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