-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Allowing .default_scope to accept a lambda makes it pretty easy to do multi-tenancy; the AR implementation is described here.
I can create a patch if there's interest in this. It looks like it may be a simple change by storing the scope object in .default_scoping instead of the scoped conditions of that scope object.
def default_scope(conditions = {}, &block)
self.default_scoping = Mongoid::Scope.new(conditions, &block)
end
def criteria(embedded = false, scoped = true)
scope_stack.last || Mongoid::Criteria.new(self, embedded).tap do |crit|
return crit.fuse(default_scoping.conditions.scoped) if default_scoping && scoped
end
end
Update: Our implementation is described here.