Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-798

Allow .default_scope to accept lambdas

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • 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.

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

              Created:
              Updated:
              Resolved: