Allow .default_scope to accept lambdas

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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.

              Assignee:
              Durran Jordan
              Reporter:
              chrisconley
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: