Block-level client-context override

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Ruby Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Instead of having to call with(...) per-model it would be beneficial to provide a simple API to handle this such as:
       

      Mongoid::Document.with(read: :secondary) do
         p = Person.find(...}.first
         u = User.find_by_id(p.id)
      end
      

      which could do something like:

      def multi_with(models, settings, &block)
        first, *rest = models
        first.with(settings) do
          if rest.empty?
            yield
          else
            multi_with(rest, settings, &block)
          end
        end
      end
      
      multi_with([ Person, User ], { read: :secondary }) do
        p = Person.find(...}.first
        u = User.find_by_id(p.id)
      end
      

              Assignee:
              Unassigned
              Reporter:
              Alex Bevilacqua
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: