-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: Query
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
ActiveRecord allows defining default scope as a class method, while Mongoid does not. To be as compatible with AR as possible, we should provide this option in Mongoid.
== Original Description ==
Nothing major just wondered why Mongoid works differently here.
At some Rails Performance Guide i read that scopes in general as well default_scope is just a macro that that is turning the given proc into a class method.
So to save a few nanoseconds of work and improve readability one should just write them as class methods.
This works for normal scopes but not for `default_scope`.
default_scope -> {
where(:created_at.gte => 1.week.ago)
}
# this should do the same as it does with ActiveRecord
def self.default_scope
where(:created_at.gte => 1.week.ago)
end