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

Allow .default_scope to accept lambdas

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0.0
    • Component/s: None

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: