I’m using the latest mongoid…
How do I do the mongoid equivalent of this active record named_scope:
class Comment
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :post
field :body, :type => String
named_scope :recent, :limit => 100, :order => 'created_at DESC'
...
end
It has to be defined like this
You can check out the mongoid documentation for scopes here
From the page
Named scopes are defined at the class level using a scope macro and can be chained to create result sets in a nice DSL.